Dividing a 9x9 2d array into 9 sub-grids (like in sudoku)? (C++)

后端 未结 3 1097
独厮守ぢ
独厮守ぢ 2020-12-10 23:23

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

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 00:12

    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 |
    +---+---+---+
    

提交回复
热议问题