Post Reply 
Numbers of Armstong WP34s
11-30-2015, 08:27 PM
Post: #2
RE: Numbers of Armstong WP34s
Instead of splitting the number into digits to calculate the sum of the cubes you can create both number and sum of the cubes from the digits. This leads to four nested loops to test 4-digit numbers.

Here's a Python program:
Code:
for a in range(10):
    p = a
    t = a**3
    for b in range(10):
        q = 10*p + b
        u = t + b**3
        for c in range(10):
            r = 10*q + c
            v = u + c**3
            for d in range(10):
                s = 10*r + d
                w = v + d**3
                if s == w:
                    print s

Result:
0
1
153
370
371
407


And this program is for the HP-42S:
Code:
{ 108-Byte Prgm }
LBL "NARCIS"
9E-3
STO 00      ; 0.009
STO 01      ; a
LBL 01      ; a-loop
RCL 01      ; a
IP
STO 05      ; p = a
3
Y↑X         ; a↑3
STO 06      ; t = a↑3
RCL 00      ; 0.009
STO 02      ; b
LBL 02      ; b-loop
RCL 02      ; b
IP
RCL 05      ; p
10
*           ; 10×p
RCL+ ST Y   ; b
STO 07      ; q = 10×p + b
X<>Y        ; b
3
Y↑X         ; b↑3
RCL+ 06     ; t
STO 08      ; u = t + b↑3
RCL 00      ; 0.009
STO 03      ; c
LBL 03      ; c-loop
RCL 03      ; c
IP
RCL 07      ; q
10
*           ; 10×q
RCL+ ST Y   ; c
STO 09      ; r = 10×q + c
X<>Y        ; c
3
Y↑X         ; c↑3
RCL+ 08     ; u
STO 10      ; v = u + c↑3
RCL 00      ; 0.009
STO 04      ; d
LBL 04      ; d-loop
RCL 04      ; d
IP
RCL 09      ; r
10
*           ; 10×r
RCL+ ST Y   ; s = 10×r + d
X<>Y        ; d
3
Y↑X         ; d↑3
RCL+ 10     ; w = v + d↑3
X=Y?        ; s = w ?
VIEW ST X
ISG 04      ; d
GTO 04      ; d-loop
ISG 03      ; c
GTO 03      ; c-loop
ISG 02      ; b
GTO 02      ; b-loop
ISG 01      ; a
GTO 01      ; a-loop
END

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Numbers of Armstong WP34s - ggauny@live.fr - 11-30-2015, 07:02 PM
RE: Numbers of Armstong WP34s - Thomas Klemm - 11-30-2015 08:27 PM



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