If you're reading this page you probably know what sudoku are. You've probably solved more of them than I have. < grin > But here's my description:

Sudoku is a logic game that operates on a nine-by-nine grid with nine three-by-three sub-blocks. The goal is to use the given initial cells to fill in all the cells of the grid with a digit from 1 to 9. The constraint is that each row, column and sub-block can contain a digit only once. I became fascinated by this program and in two different bursts of activity wrote a program to quickly solve these puzzles by iteratively applying the constraints, and all the implications of those constraints.

Here's an example puzzle:

*---*---*---*---*---*---*---*---*---*
|   |   | 6 |   | 1 |   | 9 |   |   |
*---*---*---*---*---*---*---*---*---*
|   |   |   |   |   | 8 | 7 | 4 |   |
*---*---*---*---*---*---*---*---*---*
|   |   |   |   | 2 |   | 3 | 1 |   |
*---*---*---*---*---*---*---*---*---*
| 4 |   |   |   |   | 9 |   | 8 |   |
*---*---*---*---*---*---*---*---*---*
|   |   | 5 | 2 |   | 6 | 4 |   |   |
*---*---*---*---*---*---*---*---*---*
|   | 8 |   | 3 |   |   |   |   | 2 |
*---*---*---*---*---*---*---*---*---*
|   | 1 | 7 |   | 6 |   |   |   |   |
*---*---*---*---*---*---*---*---*---*
|   | 3 | 4 | 5 |   |   |   |   |   |
*---*---*---*---*---*---*---*---*---*
|   |   | 9 |   | 3 |   | 1 |   |   |
*---*---*---*---*---*---*---*---*---*

You need perl to run this script. Hopefully you already have perl installed on your computer and its in /usr/bin/perl. Even my mom's Macintosh does, so all real computers probably already have it installed. If you don't already have perl then you might want to go here. My favorite way to install perl is: apt-get install perl thanks to Debian Linux.

Download the current solve [v2.1] version now!

Once you download it, you should let your computer know it's ok to execute it, eg with chmod 755 solve. The program will parse that puzzle description given above, but an example puzzle file that works is here. Once everything's installed ok then the following line should work:

./solve -e puzzle.txt

Big thanks to Dianne and Piper for emailing me sudoku that my program failed to solve. These lead to improvements from version 1.7 to 2.0 and then 2.1, which I think is pretty darn comprehensive at solving all reasonable sudoku by logic, without resorting to cheating. [aka guessing] Please email me if you find any sudoku that this program [v2.1] can not solve. Don't use the spam magnet email address at the bottom of the page. Use esw at alum dot mit dot edu. Sorry for the obfuscation.

-erik wile erik@wile.org [HUMANS: DO NOT USE... use address in text above]
PGP public key here
Back to main site.