Part A (
Sudoku A)
B (
Sudoku B)
C (
Sudoku C)
this question refers to the Sudoku howto posted on this website. The links are shown above. My question centers around the boolean variables declared in
Part A, such as the following.
-
boolean[][] rows= new boolean[9][9];
-
...
-
if (row[i][val]) // 'val' is already present in row 'i'
-
if the boolean values are just declared like that, how would that serve the purposes of checking whether the value is present in a row, as done in
the method "possible", shown below?
-
private boolean possible(int i, int j, int val) {
-
-
// position already taken or invalid?
-
if (rows[i][val] || columns[j][val] ||
-
squares[3*(i/3)+j/3][val])
-
return false;
-
-
// position i,j is taken now:
-
rows[i][val]= true;
-
columns[j][val]= true;
-
squares[3*(i/3)+j/3][val]= true;
-
-
board[i][j]= val+1;
-
-
return true;
-
}
-
suppose the values 1,1,7 was passed to the method 'possible.'
it would first check rows[1][7], right? and that would yield true or false.
now...rows[1][7] has not been declared true or false. How would the method
at that point know anything about the first row? in fact, how do these boolean
values know to refer to the actual sudoku board, int board[][], since these
rows[][], columns[][], and squares[][], are boolean values of their own, completely unrelated to the sudoku board int values, board[][]?
perhaps I just don't understand how this "possible" method works.
any help will be appreciated. Thank you!