Post Reply 
challenge for programmable calculators
12-22-2013, 03:01 PM (This post was last modified: 12-22-2013 03:58 PM by Thomas Klemm.)
Post: #19
RE: challenge for programmable calculators
(12-21-2013 06:15 PM)Don Shepherd Wrote:  A non-brute-force solution would greatly enlighten this rainy day.

This solution for the HP-42S reduces the amount of trials from 729 to 86 by using the symmetry of the expression.

Registers:
00: a.009
01: b.009
02: c.009
03: a
04: d = 10*a
05: e = a+b
06: f = a*b
07: g = 10*(d+b) = 10*(10*a+b)
Code:

00 { 85-Byte Prgm}
01 1.009     
02 STO 00    ; a.009 = 1.009
03 LBL 00    
04 RCL 00    ; a.009
05 STO 01    ; b.009 = a.009
06 IP        ; a
07 STO 03    ; a
08 10        
09 ×         
10 STO 04    ; d = 10*a
11 LBL 01    
12 RCL 03    ; a
13 STO 05    ; e = a
14 STO 06    ; f = a
15 RCL 01    ; b.009
16 STO 02    ; c.009 = b.009
17 IP        ; b
18 STO+ 05   ; e = a+b
19 STO× 06   ; f = a*b
20 RCL+ 04   ; d+b = 10*a+b
21 10        
22 ×         
23 STO 07    ; g = 10*(d+b) = 10*(10*a+b) = ab0
24 LBL 02    
25 RCL 07    ; ab0
26 RCL 02    ; ab0 c.009
27 IP        ; ab0 c
28 +         ; abc
29 LASTX     ; abc c
30 ENTER     ; abc c c
31 RCL+ 05   ; abc c a+b+c
32 ×         ; abc (a+b+c)*c
33 RCL× 06   ; abc (a+b+c)*a*b*c
34 1E3       ; abc (a+b+c)*a*b*c 1000
35 X≤Y?      ; (a+b+c)*a*b*c ≥ 1000 ?
36 GTO 03    
37 R↓        ; abc (a+b+c)*a*b*c
38 X=Y?      ; abc = (a+b+c)*a*b*c ?
39 STOP      ; found a solution
40 ISG 02    ; c++
41 GTO 02    
42 LBL 03    
43 RCL 01    ; b.009
44 RCL 02    ; b.009 c.009
45 X=Y?      ; b.009 = c.009 ?
46 GTO 04    
47 ISG 01    ; b++
48 GTO 01    
49 LBL 04    
50 RCL 00    ; a.009
51 RCL 01    ; a.009 b.009
52 X=Y?      ; a.009 = b.009 ?
53 GTO 05    
54 ISG 00    ; a++
55 GTO 00    
56 LBL 05    
57 END

Since we're lucky and the digits of the solutions are in the correct order I'm cheating a little as well and leave that part as an exercise.

Cheers and thanks for the challenge
Thomas

PS: This Python program does the same.
Code:

for a in range(1,10):
    d = 10*a
    for b in range(a,10):
        e = a+b
        f = a*b
        g = 10*(d+b)
        for c in range(b,10):
            h = (e+c)*f*c
            if h < 1000:
                if h == g+c:
                    print h
            else:
                break
        else:
            continue
        if b == c:
            break
    else:
        continue
    if a == b:
        break
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: challenge for programmable calculators - Thomas Klemm - 12-22-2013 03:01 PM
Proof using number theory - cruff - 12-24-2013, 05:43 PM
RE: challenge for programmable calculators - radwilliams - 12-24-2013, 05:57 PM



User(s) browsing this thread: 1 Guest(s)