(Specifically,
most of the time there is at least one cell that can
be filled in only one way for some reason, [...]; I've rarely seen
puzzles needing a search tree with more than a dozen or so nodes,
and many need no search at all, ie, there is no backtracking.)
Mine didn't
have a search tree; it just kept a list of possible
values for its cells and removed them as the pre-filled values for
the puzzle were entered (i.e. if that value were added to the cell's
row, column or box). If a cell ever wound up with only one
possibility, it would fill that value in, etc. For a properly
deterministic puzzle (and I'm given to understand that a puzzle isn't
"right" if it's not deterministic), this would result in an answer by
the time the last pre-filled value was entered.
I'm not sure what you mean by "deterministic". But there are sudoku
which have only one solution but for which that procedure does not
work. I just ran my generator with the option that says to not exclude
such cases and got (I've manually replaced three .s with -s and three
more with *s; see below):
+-------+-------+-------+
| 2 9 - | . . 1 | - 6 8 |
| . 3 . | . . 2 | 4 - . |
| . . 1 | . . . | . . . |
+-------+-------+-------+
| 4 . * | . 6 9 | . . . |
| . . 9 | . . . | 6 . . |
| . . . | 2 5 . | . . 7 |
+-------+-------+-------+
| . . . | . * . | 1 . . |
| . . 6 | 3 * . | . 5 . |
| 1 2 . | 8 . . | . 7 6 |
+-------+-------+-------+
This has only one solution. However, if you just fill in forced cells
(cells that can have been restricted to only one possibility by other
numbers), you'll find that you get stuck after placing three numbers,
the three spaces I've replaced with *s. Then my program resorts to
trying possibilities and doing backtracking when it gets stuck. The
three cells I've replaced with -s are the three cells where it's done
this when it finds the solution. (They contain 4 in the leftmost one
on the top row, 5 in the other one on the top row, and 9 in the one on
the second row.)
There's nothing nondeterministic here; the provided values do uniquely
determine the values for all the other cells. The only thing that's
interesting is _finding_ that unique solution.
The actual class assignment is still online here;
it's entertaining
reading, if nothing else. [...]
http://www.csee.umbc.edu/~tadwhite/441.f05/project.html
I find it interesting that his idea of "proper" sudoku includes no
backtracking necessary, but does not mention symmetry - though all his
sample puzzles do indeed have 180-degree rotational symmetry in the
pattern of pre-filled cells - whereas I thought the symmetry was one of
the things which made a proper sudoku but was unaware of any
prohibition on backtracking. (And, yes, my program has no trouble with
any of his examples, once the input format is converted, and resorts to
tree search on only the one he doesn't say shouldn't need it.)
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse at
rodents-montreal.org
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B