I'd be inclined to code this the other way around. - have an array of positions for each number, rather than numbers for each position. To print out the grid, make a blank 3*3 grid and run through the list of numbers once to fill it in. Then print that grid.