Bookmark this:
Sudoku Programmers :: Index

It's not busy, and not oriented for beginners, but just reading there, you could learn (or just be amazed by) some subtleties of Sudoku and programming for it.

You won't need your original grid in the brute forcer function, because there is no need to use it. If the answer lies within the set of the space that is being searched, it WILL be found, by going forward.

consider a row, by itself:
Code:
| 1 ? 3 | 4 ? 6 | 7 ? 9 |
And for this example, let's assume we could get no other info on what the possible digits for the ? squares, could be, except the obvious:

The answer lies in this search set:
258
285
528
582
825
852

Before we finish searching this set (and testing of course), we will find the correct answer to the row, above, (or, in a full puzzle, we may find that no answer is possible).

So in the solver, we set sqr 2 = 1, and that fails, then we increment sqr 2 to 2, and it succeeds. Go down one level and work with sqr 5. We set it for 1,2,3,4,5,6.7,8,9 (because our brute forcer is very basic and not too smart yet), and they all fail because of conflicts with the rest of the puzzle. So it returns up, one level. Now we set #2 to 3,4 - and they fail, but 5 succeeds, so we go down one level, and we're back to testing #5 sqr. 1 fails, but 2 succeeds, so we go down another level, and we're testing sqr #8.

How would the testing for square #8 go? Using this simplified example, can you code up a recursive function that will solve this row?

Let's say the correct answer is square 2 = 5, sqr 5 = 2, and sqr 8 = 8.

Try and find that with a recursive function, and forget (for now), the rest of your program. This will have to be the heart of your program, since your logic is very sparse. (and no amount of logic will solve every single puzzle - although they are getting close).