Let's say I have a 1D array of 81 elements, which could be thought of as representing a Sudoku board... a 9x9 matrix (every 9 elements create a new row). The question is, given an index into the 1D array, is there a closed form equation to return the square in which that element exists on the Sudoku board and can you prove the equation is correct?
For example, if you're given index 10, the result would be 0 since the 10th element is in the top left 3x3 square. If you're given index 75, the result would be 7 since the 76th element is in the bottom middle 3x3 square.
array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80] Sudoku board: [ 0, 1, 2|, 3, 4, 5|, 6, 7, 8] [ 9, 10, 11|, 12, 13, 14|, 15, 16, 17] [ 18, 19, 20|, 21, 22, 23|, 24, 25, 26] -----0----- -----1----- -----2----- [ 27, 28, 29|, 30, 31, 32|, 33, 34, 35] [ 36, 37, 38|, 39, 40, 41|, 42, 43, 44] [ 45, 46, 47|, 48, 49, 50|, 51, 52, 53] -----3----- -----4----- -----5----- [ 54, 55, 56|, 57, 58, 59|, 60, 61, 62] [ 63, 64, 65|, 66, 67, 68|, 69, 70, 71] [ 72, 73, 74|, 75, 76, 77|, 78, 79, 80] -----6----- -----7----- -----8-----