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: Thanks, Mr. Haley by Ken Haley)
Haley's Comet !!
Mr. Haley:
The reason my program was taking several minutes to run is that it tries to find all solutions, whereas yours stops at the first one. When I ran both programs to display time-of-day, my program took 0.06 seconds to find the first solution; whereas yours, being much smaller and more efficient, took 0.00 seconds. (Hard to improve on zero seconds.) [I have a 2.20 gigahertz Intel Pentium 4 with 638 Megabytes Installed Memory.]
Thanks for illustrating a much smarter programming technique than just what I have been doing up to now: creating massive redundant code.
Edited on May 15, 2005, 6:02 am
|
Posted by Penny
on 2005-05-15 05:44:29 |