I\'m trying to code a sudoku solver, and the way I attempted to do so was to have a 9x9 grid of pointers that hold the address of \"set\" objects that posses either the solu
I would create a lookup table with 81 entrys. Each entry refers to a cell in the 9x9 grid and gives you the information you need (which box, which column, which row, ...)
I use this myself (but then in python, assuming x and y go from 0 to 9 exclusive):
int bx, by;
for (bx = (x/3)*3; bx < (x/3)*3 + 3; bx++) {
for (by = (y/3)*3; by < (y/3)*3 + 3; by++) {
// bx and by will now loop over each number in the block which also contains x, y
}
}
You could calculate a block number from row and column like this:
int block = (row/3)*3 + (col/3);
This numbers the blocks like this:
+---+---+---+
| 0 | 1 | 2 |
+---+---+---+
| 3 | 4 | 5 |
+---+---+---+
| 6 | 7 | 8 |
+---+---+---+