Dividing a 9x9 2d array into 9 sub-grids (like in sudoku)? (C++)
- by kevin
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 solution or valid possible values.
I was able to go through the array with 2 for loops, through each column first and then going to the next row and repeating.
However, I'm having a hard time imagining how I would designate which sub-grid (or box, block etc) a specific cell belongs to. My initial impression was to have if statements in the for loops, such as if row < 2 (rows start at 0) & col < 2 then we're in the 1st block, but that seems to get messy. Would there be a better way of doing this?