1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
---|---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
public boolean checkColRow(int c, int r, int num) { for(int i=0; i < gridSize; i++) { if(board[c][i] == num || board[i][r] == num) return false; } return true; }
public boolean checkColRow(int c, int r, int num) { for(int i=0; i < gridSize; i++) { if(board[c][i] == num || board[i][r] == num) return false; } return true; }
public void solver(int k) { if(k == numEmpty) { printBoard(); } else { int c = array[k][0]; int r = array[k][1]; for(int i=1; i <= gridSize; i++) { if(checkColRow(c, r, i) && checkSquare(c, r, i)) { board[c][r] = i; solver(k+1); board[c][r] = 0; } } } }