While watching a rerun of NUMB3RS on TV, the mathmatician, Charlie, suggested to his dad that he should just right an algorithm to solve the Sudoku puzzles. Hmm, I could do that!
I started out writing a short vbscript that would attempt to solve the puzzle.
This could solve virtually all Easy and Moderate rated puzzles. When using attempting a Hard puzzle, it would fail when only squares with 2+ possible values remained.
Reading in a Sudoku puzzle book, they suggested a few additional methods and I added logic for these scenarios.
This allowed the script to solve several HARD puzzles that the previous script crashed on. Unfortunately, not all mulitple possible value scenarios have multiples.
Alright, now time to guess. To guess, the script does a few things.
If the first guess is wrong, it uses the post-guess values to revert the changes made. The script then attempts the second possible value in the guess. If this also fails, it reverts again, and finds another square.
During my practice runs, the script has completed 'Diabolical' level puzzles in a matter of seconds!! Solved scripts are saved to the root of C:\ in a CSV format.
| Attachment | Size |
|---|---|
| sudoku_8-4.zip | 6.83 KB |