http://www.hpmuseum.org/cgi-sys/cgiwrap ... ?read=1220
I transposed if for the DM42. Given the speed of this calculator, the solver is quite usable : solving an easy grid takes 10s and a medium grid, around a minute with USB power. I didn't tried hard grids yet...
I made a few modification:
- added a routine to clear variables before launching the main loop otherwise, the program would fail
- added a routine at the end to show the solution 3 lines by 3 lines : pres R/S to display the next lines.
- added a view to show the progression of the backtracking algorithm. The goal is to reach 80...
To use it :
1. Type in your grid using an integer for each line in registers 8 to 15. Use 0 for unknown cells.
2. Launch sudo15 and wait for the magic to happen (reg 01 reaches 80)
3. read the solution on the stack, 3 lines by 3 lines. press R/S to see next section. The solution is stored in registers 17 to 25.
Example : This is an easy grid that takes less than 10s with USB power
9 _ 3 | _ 6 8 | 5 _ 4 | --> store 903068504 in register 08
_ _ 6 | _ 3 5 | _ _ _ | --> store 6035000 in register 09
_ _ 8 | 1 _ _ | _ 3 _ | --> etc...
_ _ _ | _ 5 7 | . 6 9 |
8 _ _ | _ _ _ | _ _ 2 |
6 7 _ | 8 9 _ | _ _ _ |
_ 6 _ | _ _ 9 | 1 _ _ |
_ _ _ | 4 1 _ | 2 _ _ |
5 _ 1 | 3 7 _ | 6 _ 8 | --> store 501370608 in register 16
XEQ sudo15
and voila
9 1 3 | 7 6 8 | 5 2 4 |
4 2 6 | 9 3 5 | 7 8 1 |
7 5 8 | 1 2 4 | 9 3 6 |
1 3 4 | 2 5 7 | 8 6 9 |
8 9 5 | 6 4 1 | 3 7 2 |
6 7 2 | 8 9 3 | 4 1 5 |
2 6 7 | 5 8 9 | 1 4 3 |
3 8 9 | 4 1 6 | 2 5 7 |
5 4 1 | 3 7 2 | 6 9 8 |
Enjoy...
Code: Select all
00 { 402-Byte Prgm }
01▸LBL "SUDO15"
02 XEQ 00
03 CF 02
04 CF 03
05 -1
06 STO 01
07▸LBL 02
08 1
09 XEQ 06
10 RCL 07
11 XEQ 07
12 RCL 07
13 X>0?
14 XEQ D
15 80
16 RCL 01
17 X≠Y?
18 GTO 02
19 -1
20 STO 01
21▸LBL E
22 VIEW 01
23 80
24 RCL 01
25 X=Y?
26 GTO 12
27 1
28 XEQ 06
29 RCL 07
30 X>0?
31 GTO E
32 XEQ 07
33▸LBL 08
34 9
35 RCL 06
36 X=Y?
37 GTO C
38 1
39 +
40 XEQ 07
41 RCL 06
42 XEQ 05
43 CF 02
44 RCL 02
45 XEQ 09
46 FS? 02
47 GTO 08
48 RCL 03
49 XEQ 09
50 FS? 02
51 GTO 08
52 RCL 04
53 XEQ 09
54 FS? 02
55 GTO 08
56 RCL 06
57 XEQ D
58 GTO E
59▸LBL C
60 -1
61 XEQ 06
62 X>0?
63 GTO C
64 RCL 06
65 SF 03
66 XEQ D
67 CF 03
68 GTO 08
69▸LBL 09
70 XEQ 01
71 RCL÷ 00
72 IP
73 2
74 ÷
75 FP
76 X>0?
77 SF 02
78 R↓
79 R↓
80 9
81 +
82 GTO 05
83▸LBL 05
84 STO 00
85 1
86 -
87 2
88 X<>Y
89 Y↑X
90 X<> 00
91 RTN
92▸LBL 01
93 ENTER
94 ENTER
95 26
96 XEQ 03
97 RCL IND "I"
98 RTN
99▸LBL 03
100 +
101 STO "I"
102 R↓
103 RTN
104▸LBL D
105 XEQ 05
106 RCL 02
107 XEQ B
108 RCL 03
109 XEQ B
110 RCL 04
111▸LBL B
112 XEQ 01
113 RCL 00
114 FS? 03
115 +/-
116 +
117 X<>Y
118 26
119 XEQ 03
120 STO IND "I"
121 R↓
122 9
123 +
124 GTO 05
125▸LBL 07
126 X<> 06
127 STO 00
128 RCL 02
129 17
130 XEQ 03
131 RCL IND "I"
132 RCL 06
133 RCL- 00
134 RCL× 05
135 +
136 STO IND "I"
137 RTN
138▸LBL 06
139 STO+ 01
140 RCL 01
141 RCL 01
142 9
143 ÷
144 IP
145 STO 02
146 9
147 ×
148 -
149 STO 03
150 3
151 ÷
152 RCL 02
153 3
154 ÷
155 IP
156 3
157 ×
158 +
159 STO 04
160 8
161 RCL- 03
162 10↑X
163 STO 05
164 RCL 02
165 17
166 XEQ 04
167 STO 06
168 RCL 02
169 8
170 XEQ 04
171 STO 07
172 RTN
173▸LBL 04
174 XEQ 03
175 RCL IND "I"
176 RCL÷ 05
177 IP
178 10
179 ÷
180 FP
181 10
182 ×
183 RTN
184▸LBL 00
185 SIZE 35
186 7
187 STO "I"
188 CLX
189▸LBL 10
190 STO IND "I"
191 DSE "I"
192 GTO 10
193 34.016
194 STO "I"
195 CLX
196▸LBL 11
197 STO IND "I"
198 DSE "I"
199 GTO 11
200 RTN
201▸LBL 12
202 CLST
203 RCL 17
204 RCL 18
205 RCL 19
206 STOP
207 CLST
208 RCL 20
209 RCL 21
210 RCL 22
211 STOP
212 CLST
213 RCL 23
214 RCL 24
215 RCL 25
216 RTN
217 END