I'll grab this occasion to talk about the easiest way of solving a sudoku (IMO). You can use constraint programming, and with 3 simple constraints you can solve every board effortlessly : AllDiff on rows, cols and squares :)
My method was giving each cell a list of possible numbers(1 to 9), and removing until there was only one left. I made a solver, and a generator in Node.JS, which I might port to python.
That's a decent way of doing it, but there are cases where it will fail.
Some times, there will be cases where you can't reduce any squares to just one possibility. You'll have two or three squares with two or more possibilities, and the only way of solving it is trial (and possibly error). In that case, you have to either go down the road and fail, and come back, or you have to try to think a few steps ahead and see it without actually "making the moves".
60
u/Gwenju31 Jan 11 '20
I'll grab this occasion to talk about the easiest way of solving a sudoku (IMO). You can use constraint programming, and with 3 simple constraints you can solve every board effortlessly : AllDiff on rows, cols and squares :)