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:
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): Result: 0 1 153 370 371 407 And this program is for the HP-42S: Code: { 108-Byte Prgm } 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): 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): 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): 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. |