This popular Japanese number puzzle has just one easy rule:
In every Row, every Column and every 3x3 sub-grid, all the numbers from 1 to 9 should appear, but only once in each row, column and sub-grid.
+------+-------+------+
| 0 0 0 | 7 0 0 | 4 0 0 |
| 0 3 0 | 0 9 0 | 0 2 0 |
| 4 0 0 | 0 0 5 | 0 0 0 |
+------+-------+------+
| 0 0 8 | 0 0 0 | 0 0 5 |
| 0 9 0 | 0 3 0 | 0 7 0 |
| 6 0 0 | 0 0 0 | 3 0 0 |
+------+-------+------+
| 0 0 0 | 4 0 0 | 0 0 6 |
| 0 7 0 | 0 2 0 | 0 9 0 |
| 0 0 5 | 0 0 8 | 0 0 0 |
+------+-------+------+
Replace the 0's with the digits required to satisfy the rule.
(In reply to
re(3): Haley's Comet vrs. Penny's Loafer: And the winner is.... by Ken Haley)
Ken, did you mean to say that your program ran in 1 minute 3 seconds ? Because I don't see how it could have exhausted all the possibilities in 1.03 seconds.
I managed to get my program under a minute, by discarding any attempts at recursive logic (I got tired of seeing that "stack" error), and instead going after the 81 "cells" in an optimized "3 x 3 subgrid" order.
If the subgrids are:
A B C
D E F
G H I
...then going at them in order B-E-D-F-H-A-C-G-I (the idea being to vary the middle subgrid E, which only has one initial nonzero number, a relatively few times) is done by my program in less than one minute (1:40:43 - 1:41:25).
If anyone is interested, the modified program has been replaced in my original post titled "A popular game in my neighborhood..."
|
Posted by Penny
on 2005-05-18 19:53:41 |