I am having trouble with dividing a 2D array into boxes, like in Sudoku. I have an array of squares in my board object, and I want to divide them into 2x3 or 3x3 boxes, The box objects have a 1D array to keep track of the squares.
k is the box number, in a 9x9 sudoku, the boxes will be numbered 0 through 8.
int l = 0;
for(int i=k*a; i<k*a+a;i++){
for(int j=k*b;j<k*b+b;j++){
narray[l]=brd.getSquare(i,j);
brd.getSquare(i,j).setBox(this);
l++;
}
This gets the first box right, but goes off after that. I've been thinking about this for hours now, and I can't seem to wrap my head around it. Does anyone have a neat trick for this?