Better comments

This commit is contained in:
Imbus 2023-12-05 16:13:57 +01:00
parent 24463fe920
commit f84cccc1b5

View file

@ -38,6 +38,7 @@ public class Solver implements SudokuSolver {
return false; return false;
} }
// If row is 9, drop down to the next column, if column is 9, we are done
if (row == 9) { if (row == 9) {
row = 0; row = 0;
if (++col == 9) { if (++col == 9) {
@ -45,13 +46,17 @@ public class Solver implements SudokuSolver {
} }
} }
// If we have a "number" in the current cell
// recursively call solve() on the next cell
if (board[row][col] != 0) { if (board[row][col] != 0) {
return solve(row + 1, col); return solve(row + 1, col);
} }
// Check for legal values in the current cell
for (int val = 1; val <= 9; ++val) { for (int val = 1; val <= 9; ++val) {
if (legal(row, col, val)) { if (legal(row, col, val)) {
board[row][col] = val; board[row][col] = val;
// When we find a legal value, recursively call solve() on the next cell
if (solve(row + 1, col)) { if (solve(row + 1, col)) {
return true; return true;
} }