user1971804 - 4 months ago 28

Java Question

I want to create 9x9 sudoku matrix with integers 1-9.

I can create 3x3 version but when it comes to 9x9 I cant figure out the algorithm for that.

Any ideas how I would achieve that?

Answer

The algorithm (at least a basic one) is quite simple.

- Start in the upper left most square and pick a random number
- Work your way along the row and pick a random number (excluding ones previously used on that row)
- Once a row is complete move to the next row
- When working on any but the first row as well as checking numbers in previous columns also check numbers in previous rows of that column
- Algorithm terminates when reaching bottom right of the grid