Well Quite!


The Rants, Raves, and Rituals of Matthew Sackman
Friday, September 23rd, 2005

Sudoku Solver

Well, this is my Sudoku solver that I wrote. It's written in Java and you need a Java 5.0 (aka 1.5) JVM to run it. If you don't have that then you won't be able to see the solver in all its glory. I would give some instructions on getting the Java JVM installed but it varies so much from platform to platform that it's going to be painful. It also varies on browser. Grrr.

Anywho, if on the off chance that it is all working for you, here's how to use it:

  • Left click increases the number in each cell
  • Right click decreases the number
  • Click on Solve to solve the puzzle
  • Click on Reset to go back to just the numbers you put in
  • Click on Step Mode to put the solver into Step mode. Then, clicking on Step will allow you to step through the solution one square at a time.

There isn't much validation: it will allow you to set every square to the same value if you want to, but then solving it won't get very far. It won't actually crash in those situations - it remains fully usable.

It's also very possible that there are certain classes of puzzles that it can't solve but can be solved by humans. If you find some of these then please tell me and I'll thank you, put it on my todo pile and in the distant future may get around to improving my solver...

Sudoku Solver Applet

This is a completely clean-room implementation - I didn't do any research or browsing to look at what other solvers out there are or do. It is not a brute-force solver (I believe many of them are). A brute force solver just tries every possible combination until it finds one that works. This is useless if you're trying to find out how to go about solving a particular puzzle. My solver uses deduction to work out where numbers can go: this is the point of the step mode as it allows you to see what the solver is doing and you should be able to work out why it's doing each move.

If you want the source code, then download it. Licensed under GPL v2 only.