[VA] Short & Sweet Math Challenges #23: "May the 4th Be With You !" Special
|
05-25-2018, 01:57 AM
Post: #33
|
|||
|
|||
RE: [VA] Short & Sweet Math Challenges #23: "May the 4th Be With You !" ...
Thank you VA for your kind encouragement to post, it was a pleasure to work on for a flight (and a night) so I'm glad I get to share.
Another way to define the selfie is an n-digit number which is identical to the sum of the n-the power of its digits, but does not end in a 0. To constrain the search space, I used two features: (1) One can always rank order the digits of a number in a monotonously falling fashion (each digit is smaller or equal than the prior one (2) As soon as one has a sum of n-th power of digits which is larger than 10^n, one can stop as all combination of digits to the right will yield unqualified results. The combined application of the above allows to cut of quite substantial swaths of the search tree. The implementation is based on the specific limitations of the HP41, namely: 1) It can only deal with at most 6 subroutine levels. This makes a recursive approach unfortunately not possible on the 41, yet I would not be surprised if this is possible, indeed advisable for the 71b 2) The 41 is very very slow in dealing with direct number entries. As such, virtually all numbers are stored in registers for faster processing 3) Akin to the JPC rom, my version uses my beloved Sandbox module, for the use of INCX, DECX, and AINT 4) Once a number has been found with a sum of the n-th powers of its digits between 10^n and 10^(n-1), the number is then checked to see if it is a selfie, aka the sum of its digts raised to the n-th power, using AINT and ATOX. The code below takes as an entry the number of digits and then runs until all n-digit selfies are found. Adding a loop over all digits would be trivial but was not done for the purpose of easier exploration of the results of the code, timing, etc. Code:
Very much looking forward to comments, in particular ways to make it smarter. Cheers, PeterP |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)