Numbers of Armstong WP34s - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: Not HP Calculators (/forum-7.html) +--- Forum: Not quite HP Calculators - but related (/forum-8.html) +--- Thread: Numbers of Armstong WP34s (/thread-5244.html) Numbers of Armstong WP34s - ggauny@live.fr - 11-30-2015 07:02 PM Hi all, I have made a little routine to know how are numbers of Armstrong, it is a curiosity arithmetic like this : A one is when the sum of the digits of the number cube is egal to the number, as example : 1 is because, of course, 1^3 is 1, 153 is too because 1^3+5^3+3^ is 153. In my knowledge only is 1, 153,370,371,407. I think it is all but not sure am-I. For cumfortable use I merged 2 routines in one. Did you notice that I use goods ideas from forum like inc x and Dieter's 'DIVMOD' as if theses was built'in functions ? Code: ``` fLBL'NAR'  ; stand for "Number of ARmstrong 2000   ; a limit STO 03 0 STO 04 INC 04  ; it is 1,2,3,..... RCL 04  XEQ'TT1' DSZ 03   ; to not over the 2000 limit BACK 04 END fLBL'TT1' FILL EXPT INC X STO 01 DROP #010 RMDR X^3 STO+ 02 DROP #010 IDIV ENTER DSZ 01 BACK 009 RCL 02 X=? T PSE 30  ; to have time to read and note on a sheet of paper 0 STO 01 0 STO 02 END.``` Well, I am aware that serve for nothing, but it is funy, no ? Like say Dieter : as usual comments are welcome. RE: Numbers of Armstong WP34s - Thomas Klemm - 11-30-2015 08:27 PM 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 RE: Numbers of Armstong WP34s - Dave Frederickson - 11-30-2015 09:21 PM (11-30-2015 07:02 PM)ggauny@live.fr Wrote:  A one is when the sum of the digits of the number cube is egal to the number ... This is only true for 3-digit Armstrong Numbers. For an n-digit Armstrong Number, each digit is raised to the n-th power. So for 4-digit Armstrong Numbers, each digit is raised to the 4th power, not the 3rd. 1 is an Armstrong Number because 1^1=1, not 1^3=1. Dave RE: Numbers of Armstong WP34s - ggauny@live.fr - 12-01-2015 06:35 AM Hi all, I was ignoring that Armstrong's numbers was posssible after 3 digits, I am going to search for 4, 5... But I am afraid the time to calcul solutions. I appreciate your's intervention and also the program of Thomas for 42s, but I am a bit with difficulty to apprehend Python approach. Good days for all. RE: Numbers of Armstong WP34s - Thomas Klemm - 12-01-2015 10:11 AM (12-01-2015 06:35 AM)ggauny@live.fr Wrote:  also the program of Thomas for 42s, but I am a bit with difficulty to apprehend Python approach. You can just replace the exponent 3 by 4: Click run Code: ```for a in range(10):     p = a     t = a**4     for b in range(10):         q = 10*p + b         u = t + b**4         for c in range(10):             r = 10*q + c             v = u + c**4             for d in range(10):                 s = 10*r + d                 w = v + d**4                 if s == w:                     print s``` Result: 0 1 1634 8208 9474 => None Cheers Thomas PS: If you want to go further with n you might extract that loop into a function that can be called recursively: Click run Code: ```def armstrong(n, i, a, b):     if i == 0:         if a == b:             print a     else:         for d in range(10):             armstrong(n, i-1, 10*a + d, b + d**n)              for n in range (1, 7):     print "n = %d" % n     armstrong(n, n, 0, 0)     print``` Result: n = 1 0 1 2 3 4 5 6 7 8 9 n = 2 0 1 n = 3 0 1 153 370 371 407 n = 4 0 1 1634 8208 9474 n = 5 0 1 4150 4151 54748 92727 93084 n = 6 0 1 548834 => None RE: Numbers of Armstong WP34s - ggauny@live.fr - 12-01-2015 11:14 AM Hallo Thomas, Very thanks for your explanation, I will do an another routine to find with exposants up to three. I have notice that if I am strangled it is permis to write a bit in french to be more clear, Marcus say the same thing of you. Thanks again. RE: Numbers of Armstong WP34s - Thomas Klemm - 12-01-2015 01:07 PM There's another online tool to visualize Python. Just copy this: Code: ```def armstrong(n, i, a, b):     if i == 0:         if a == b:             print a     else:         for d in range(10):             armstrong(n, i-1, 10*a + d, b + d**n) armstrong(3, 3, 0, 0)``` Paste it into the text-box and press [Visualize Execution]. Now you can step [Forward >] and [< Back] through the program just as you are used to from your calculators. However stepping back will undo the operation. Cheers Thomas RE: Numbers of Armstong WP34s - Albert Chan - 07-30-2018 12:58 AM I had solved Armstrong Numbers problem many years ago. It searched all Armstrong Numbers (digits > 1) in 6 minutes on my laptop. That is a huge 10^60 search space ! This is the gist of my routine: If pattern 543 is checked, other permutations (345, 354, 435, 453, 534) can be skipped. All permutations is going to produce the same sum anyway. So, 1 check = 3! = 6 tests Digits pattern not reached 3 digits can be skipped: 100 110 111, 200, 210, 211, 220, ..., 432 Sum of over 3-digits can also be skipped: 964, 965, 966, 970, 971 ..., 988, 990, ... 999 Patterns to check = 433, 440, 441 ..., 963 (*) The trick is to design how the pattern incremented. You can guess the algorithm from above example. Have you seen it ? Combinatorial problem is fun ! :-) (*) my code actually search to 988 To speed up the code, it need a simple test for endpoint. So, the loop stop if the next pattern had too many 9's in it.