This program is Copyright © 2007 by Jean-Marc Baillard and is used here by permission.
This program is supplied without representation or warranty of any kind. Jean-Marc Baillard and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.
Overview
-"Le compte est bon" is a French TV game:
-6 numbers ( n1 , n2 , n3 , n4
, n5 , n6 ) are choosen at random among the
24 integers:
1 - 1 - 2 - 2 - 3 - 3 - 4 - 4 - 5 - 5 - 6 - 6 - 7 - 7 - 8 - 8 - 9 - 9 - 10 - 10 - 25 - 50 - 75 - 100 ( for instance 1 - 9 - 8 - 4 - 3 - 100 )
and you have to find another random number N ( between 100 and
999 inclusive ) , say N = 629 , using the 6 numbers above (
or less )
and the 4 basic operations: addition, subtraction, multiplication,
division.
-For example, one solution of the above problem is:
100 - 1 = 99
99 / 3 = 33
33 + 4 = 37
9 + 8 = 17
37 * 17 = 629
-A solution has - at most - 5 operations and the same number cannot
be used several times.
-More exactly, you can use "ni" twice or less if there are
2 "ni"s
and ---------------- once --------------- is 1
"ni"
-The following program can help you to find one or several solution(s)
to this problem.
Program Listing
Data Registers: •
R01 = n1 • R02 = n2 ..........
• R06 = n6 • R07 = N
( these 7 registers are to be initialized before executing "LCEB"
)
R00 & R08 thru R17: temp
Flags: F05-F06-F07
Subroutines: /
01 LBL "LCEB"
02 6
03 STO 12
04 5
05 STO 13
06 STO 16
07 4
08 STO 14
09 STO 17
10 3
11 STO 00
12 STO 15
13 LBL 01
Lines 01 to 39 and 127 to 356 search a solution where the result of an
operation is immediately used in the next one.
14 RCL 07
If - at this step - no solution is found, lines 40 thru 124 add a few other
combinations.
15 RCL 07
16 RCL 01
17 /
18 STO 08
19 CF 05
20 X#Y?
21 FRC
22 X=0?
23 XEQ 02
24 RCL 07
25 RCL 01
26 -
27 STO 08
28 SF 05
29 XEQ 02
30 RCL 07
31 RCL 01
32 +
33 STO 08
34 XEQ 02
35 RCL 01
36 X<> IND 12
37 STO 01
38 DSE 12
39 GTO 01
40 6.001
41 STO 12
42 STO 13
43 LBL 12
44 RCL 07
45 RCL 01
46 RCL 02
47 +
48 STO 08
49 /
50 STO 09
51 CF 06
52 FRC
53 X=0?
54 XEQ 03
55 RCL 07
56 RCL 07
57 RCL 01
58 RCL 02
59 X=Y?
60 GTO 00
61 -
62 ABS
63 STO 08
64 /
65 STO 09
66 X#Y?
67 FRC
68 X=0?
69 XEQ 03
70 LBL 00
71 RCL 01
72 RCL 02
73 X<Y?
74 X<>Y
75 STO Z
76 *
77 X=Y?
78 GTO 00
79 STO 08
80 RCL 07
81 -
82 ABS
83 STO 09
84 SF 06
85 XEQ 03
86 RCL 07
87 RCL 08
88 +
89 STO 09
90 XEQ 03
91 RCL 07
92 RCL 01
93 RCL 02
94 X>Y?
95 X<>Y
96 /
97 STO 08
98 -
99 STO 09
100 FRC
101 X#0?
102 GTO 00
103 XEQ 03
104 RCL 07
105 RCL 08
106 +
107 STO 09
108 XEQ 03
109 LBL 00
110 RCL 02
111 X<> IND 13
112 STO 02
113 DSE 13
114 GTO 12
115 RCL 12
116 INT
117 2
118 -
119 ST+ 13
120 RCL 01
121 X<> IND 12
122 STO 01
123 DSE 12
124 GTO 12
125 "Nb NOT FOUND"
126 PROMPT
127 LBL 02
128 RCL 02
129 RCL 08
130 X=Y?
131 GTO 10
132 X<Y?
133 X<>Y
134 STO Z
135 X<>Y
136 /
137 STO 09
138 CF 06
139 X#Y?
140 FRC
lines 132 to 141 actually uses sup(a,b)/inf(a,b) instead of
a/b ( thus, more solutions may be found )
141 X=0?
and they avoid the divisions by 1
142 XEQ 03
143 FS? 05
144 GTO 00
145 RCL 08
146 RCL 02
147 -
148 ABS
likewise, calculating | a - b | produces more solutions than
a - b
149 STO 09
150 SF 06
151 XEQ 03
152 RCL 08
153 RCL 02
154 +
155 STO 09
156 XEQ 03
157 LBL 00
158 RCL 02
159 X<> 03
160 X<> 04
161 X<> 05
162 X<> 06
163 STO 02
164 DSE 13
165 GTO 12
166 RCL 16
167 STO 13
168 RTN
169 LBL 03
170 RCL 03
171 RCL 09
172 X=Y?
173 GTO 09
174 X<Y?
175 X<>Y
176 STO Z
177 X<>Y
178 /
179 STO 10
180 CF 07
181 X#Y?
182 FRC
183 X=0?
184 XEQ 04
185 FS? 06
186 GTO 00
187 RCL 09
188 RCL 03
189 -
190 ABS
191 STO 10
192 SF 07
193 XEQ 04
194 RCL 09
195 RCL 03
196 +
197 STO 10
198 XEQ 04
199 LBL 00
200 RCL 03
201 X<> 04
202 X<> 05
203 X<> 06
204 STO 03
205 DSE 14
206 GTO 03
207 RCL 17
208 STO 14
209 RTN
210 LBL 04
211 RCL 04
212 RCL 10
213 X=Y?
214 GTO 08
215 X>Y?
216 X<>Y
217 ENTER^
218 SIGN
219 X=Y?
220 GTO 00
division & multiplication by 1 are skipped
221 RDN
222 /
223 STO 11
224 FRC
225 X=0?
226 XEQ 05
227 RCL 04
228 RCL 10
229 *
230 STO 11
231 XEQ 05
232 LBL 00
233 FS? 07
234 GTO 00
235 RCL 10
236 RCL 04
237 -
238 ABS
239 STO 11
240 XEQ 05
241 RCL 04
242 RCL 10
243 +
244 STO 11
245 XEQ 05
246 LBL 00
247 RCL 04
248 X<> 05
249 X<> 06
250 STO 04
251 DSE 15
252 GTO 04
253 RCL 00
254 STO 15
255 RTN
256 LBL 05
257 RCL 06
258 RCL 11
259 X=Y?
260 GTO 07
261 RCL 05
262 -
263 X=0?
264 GTO 07
265 ABS
266 RCL 06
267 X=Y?
268 GTO 06
269 RCL 11
270 RCL 05
271 +
272 X=Y?
273 GTO 06
274 RCL 11
275 RCL 05
276 X>Y?
277 X<>Y
278 /
279 RCL 06
280 X=Y?
281 GTO 06
282 RCL 11
283 RCL 05
284 *
285 X#Y?
286 RTN
287 LBL 06
288 RCL 11
289 RCL 05
290 RCL 06
291 XEQ 00
292 LBL 07
293 RCL 10
294 RCL 04
295 RCL 11
296 XEQ 00
297 LBL 08
298 RCL 09
299 RCL 03
300 RCL 10
301 XEQ 00
302 LBL 09
303 RCL 12
304 FRC
305 X#0?
306 GTO 11
307 RCL 08
308 RCL 02
309 RCL 09
310 XEQ 00
311 LBL 10
312 RCL 07
313 RCL 01
314 RCL 08
315 GTO 00
316 LBL 11
317 RCL 08
318 RCL 01
319 RCL 02
320 XEQ 00
321 RCL 07
322 RCL 08
323 RCL 09
324 LBL 00
325 FIX 0
326 CF 29
327 X<Y?
328 X<>Y
329 STO T
330 X<>Y
331 CLA
332 ARCL Y
333 +
334 X=Y?
335 "~+"
append +
336 X<> T
337 LASTX
338 -
339 X=Y?
340 "~-"
append -
341 X<> T
342 LASTX
343 ST/ T
344 *
345 X=Y?
346 "~*"
append *
347 X<> T
348 X=Y?
349 "~/"
append /
350 ARCL L
351 "~="
append =
352 ARCL Y
353 FIX 4
354 SF 29
355 PROMPT
356 END
( 513 bytes / SIZE 018 )
Example1: 75 - 100 - 25 - 3 - 9 - 6 // 758 Store these 7 numbers into R01 thru R07 respectively
XEQ "LCEB" >>>> "75+3=78"
( in 1 minute )
R/S "78/6=13"
R/S "100-13=87"
R/S "87*9=783"
R/S "783-25=758"
Example2: 4 - 7 - 50 - 1 - 4 - 100 // 903 4 STO 01 ......................... 903 STO 07
XEQ "LCEB" >>>> "100/4=25"
( in 4 minutes )
R/S "25-4=21"
R/S "50-7=43"
R/S 43*21=903"
Example3: 3 - 7 - 7 - 50 - 1 - 8 // 947 3 STO 01 ............................ 947 STO 07
XEQ "LCEB" >>>> the HP-41 displays "Nb NOT FOUND" about 6 minutes later
-However, there is a solution ( see below )
Remarks:
-Press XEQ 10 to display again a solution in 1 operation
----- XEQ 09 ---------------------------- 2
----------s
----- XEQ 08 ---------------------------- 3
-----------
----- XEQ 07 ---------------------------- 4
-----------
----- XEQ 06 ---------------------------- 5
-----------
-In order to decrease the execution time, flags F05 F06 F07 are used
to avoid 2 successive additions and/or subtractions
in the beginning of the search ( i-e at the end of the solutions
).
-Additions and subtractions are only computed after a division or a
multiplication and a very simple result like 100 + 7 = 107 ,
107 + 25 = 132 cannot be found!
( delete lines 157 - 144 - 143 - 28 - 19 to allow this
kind of solutions )
-Moreover, the multiplication doesn't appear in the beginning of the
tree ( so, a solution never ends by a division )
and many other solutions are skipped.
-Despite all these limitations, this program can solve about 90% of
the soluble problems! ( only 80% if you delete lines 40 to 124 )
-Execution times are usually a few minutes ( less than 20 minutes apparently
)
-Improvements are easy to make: delete all the lines involving flags
F05 F06 F07 and a solution with 5 additions is now possible.
-Unfortunately, execution time can reach several hours... unless you
are using an emulator like V41 in turbo mode,
( the several hours are reduced to less than 1 minute! )
-On the other hand, you can also add other operations:
for instance, add RCL 07 RCL 01 * STO
08 XEQ 02 after line 23 and try example 3 again
-Your HP-41 now yields in 48 seconds:
"50+8=58"
R/S
"58*7=406"
R/S
"406*7=2842"
R/S
"2842-1=2841"
R/S
"2841/3=947"
-There are 2 minor defects:
1-The solution in zero operation: 100 = 100
cannot be found, but a calculator is not absolutely necessary to find this
result!
2-The HP-41 displays "2+*2=4" instead of "2+2=4" or "2*2=4"
-Of course, this program can use other integers:
-For instance, with 32 - 41 - 55 - 48 - 49 - 67 //
2007
XEQ "LCEB" >>>> "49-41=8"
R/S "48/8=6"
R/S "67-6=61"
R/S "61*32=1952"
R/S "1952+55=2007"
Go back to the HP-41 software library
Go back to the general software library
Go
back to the main exhibit hall