MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / check

Method check

Backtracking/Sudoku.js:17–39  ·  view source on GitHub ↗
([y, x], value)

Source from the content-addressed store, hash-verified

15 }
16
17 check([y, x], value) {
18 // checks if the value to be added in the board is an acceptable value for the cell
19
20 // checking through the row
21 for (let i = 0; i < 9; i++) {
22 if (this.board[i][x] === value) return false
23 }
24 // checking through the column
25 for (let i = 0; i < 9; i++) {
26 if (this.board[y][i] === value) return false
27 }
28
29 // checking through the 3x3 block of the cell
30 const secRow = Math.floor(y / 3)
31 const secCol = Math.floor(x / 3)
32 for (let i = secRow * 3; i < secRow * 3 + 3; i++) {
33 for (let j = secCol * 3; j < secCol * 3 + 3; j++) {
34 if (y !== i && x !== j && this.board[i][j] === value) return false
35 }
36 }
37
38 return true
39 }
40
41 solve() {
42 const [y, x] = this.findEmptyCell()

Callers 1

solveMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected