feb. 12 2006 Sudoku solver

By Peter Nederlof, http://www.xs4all.nl/~peterned/.
Credits and thanks to Frank Verbruggen and Arnoud Berendsen.

This is a rule based sudoku solver. Basically it applies a certain rule, and then changes its approach based on the effect (solving or affecting any cells) of the rule that was applied. The script uses the following rules in a - currently hardcoded - strategy. Rows, columns and 3x3 squares are referred to as a "selection" for brevity:

  1. If a cell is the last one within a selection to contain a certain number; conclude that number.
  2. If n cells of a selection contain exactly n options (like 2,7 and 2,7); remove these options from the remaining cells of the selection. This is enabled for sets of 2 and 3 options, even though in theory it could also be a required strategy for larger sets in very evil sudokus.
  3. If the cells of a row or column that intersect with a square are the only ones that contain a specific number in that same square, remove the number from the cells of the row or column that do not intersect with the square, since it is certain that they may not contain that number anymore.

Eliminating options from a selection when a number has been concluded is not a strategy rule. This simply happens everytime only 1 option remains for a certain cell, and can cascade all the way to the last cell. A future version will have a dropdown box in which you can select the strategy (order of rules) that is applied. Note that while I've succesfully tested this script with several evil sudokus from websudoku.com, I do not claim that this solver is capable of solving any solvable sudoku. In fact, the built in limit described in rule #2 and the current strategy might very well cause it to fail every now and then.