A Sudoku puzzle solver with algorithm in F# and UI in C# Winforms
Most Sudoku solvers I came across simply chose to implement Peter Norvig's method, but I decided I'd rather use the same method I use when solving the puzzle with pen-and-paper.
The easiest step for finding the value for a particular cell, is to find an empty cell and then figure out what it can't be.
For example, lets consider the following board taken from the Guardian Easy Sudoku #4,612 from Mon 18 Nov, 2019.
In the above initial board, concentrate on the 9x9 square in the middle-left of the board, and in this square, look at the cell in the very centre.
We can instantly tell that value of this cell can't be 3 or 5
because of other values in the 9x9 square. We can also tell that is can't be 1, 3 or 6
because of other cells in the same column. Finally, from analysing the values in the rest of the row we can also tell that it can't be 2, 3, 7, 8, or 9
. Putting all this information together and we know the cell can't be 1, 2, 3, 5, 6, 7, 8 or 9
, and must therefore be 4
.
Having found all the easy cells, we find ourselves with the following board:
There are no more easy solutions to be found, but let's consider the central 9x9 square.
This 9x9 square is missing the numbers 4, 5 and 6
. The numbers 4 and 5
could conceivably go in any of three available cells, but the number 6
cannot be on the top row because of the other 6
in the 9x9 square to the right. Therefore the 6
must be in the empty cell on the bottom row of the 3x3 square.
Brute force. Still to be implemented.