| Size | Region | |Regions| | Digits |
|---|---|---|---|
| 4><4 | 2><2 | 4 | 1,2,3,4 |
| 6><6 | 3><2 | 6 (2><3 layout) | 1,2,3,4,5,6 |
| 9><9 | 3><3 | 9 | 1,2,3,4,5,6,7,8,9 |
| 16><16 | 4><4 | 16 | 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F |
The elegance and intrigue of the puzzle comes from
Permutations: A step to a simple program
Each row, column and region has the same digits in various orders.
These are called permutations.
The ideal program would read something like:
Ideally the perm statement would either test a known list, or fill in blanks in a list, and it should, if necessary try other permutations in turn until they fit.
Prolog makes this trivial.
Prolog
Prolog is a useful prototyping tool.
I like to have fashionable examples in my CSci320 class.
I developed one from the first Harry Potter book.
You can express the problem in Prolog language and it will search for a solution.
Sudoku Simply Solved
As I expected this work well with small (4><4) examples
[ ../cs320/prolog/sudoku4.plg ]
Demo.
I knew it would need optimization to tackle a 9><9 problem.
Key optimizations
No longer simple: [ ../cs320/prolog/sudoku9.plg ]
It still takes hours to run.
Sudoku Slowly Solved
The reason is simple.
| N | N! | (N!)^N | Approximately | Times |
|---|---|---|---|---|
| 1 | 1 | 1 | 1 | |
| 2 | 2 | 4 | 4*10^0 | |
| 3 | 6 | 216 | 2*10^2 | |
| 4 | 24 | 331,776 | 3*10^5 | <0.1 second |
| 5 | 120 | 24,883,200,000 | 2*10^11 | |
| 6 | 720 | ... | 10^17 | |
| 7 | 5,040 | ... | 10^26 | |
| 8 | 40,320 | ... | 10^37 | |
| 9 | 362,880 | ... | 10^50 | 3..4 hours |
| ... | ... |
Often simple solutions are not feasible.
Next:
(Fast solutions to sudoku): Dr. Kerstin Voigt's work:
[ seminar.html ]
Links
(sudoku seminar plan):
[ sudoku.html ]
(Wikipedia): A social encyclopedia
[ http://www.wikipedia.org/ ]
(Notes on the mathematics of Sudoku): demonstration of MATHS
[ ../maths/ ]
in action
[ sudoku.maths.html ]
. . . . . . . . . ( end of section Sudoku Solving with a Computer) <<Contents | End>>