Post Reply 
Programming puzzle: Longest list of regular numbers?
01-17-2021, 09:02 PM (This post was last modified: 01-18-2021 06:02 PM by C.Ret.)
Post: #33
RE: Programming puzzle: Longest list of regular numbers?
Hi,

I may suggest changing your algorithm, I get up to the 3428th in 2min7sec on my HP-28S.
The HP-50g have much more punch than my ageless HP-28S. I am sure you will break easily my record !

Feel free to adapt this HP-28S style code;
Code:
HAM:
« → r « HRAZ 
        WHILE T r <
        REPEAT
            "Enumaring..." 1 DISP
            1 X + 'X' STO
            0  X LA * FOR y
              X LB * y LC * - IP → z
                  « IF 'E' y 1 + GET z < THEN
                                       'E' y 1 + z PUT
                                         N 1 + 'N' STO
                      'H' y L3 * z L5 * + X L2 * -
                           DUP -1250 * IP 1 + SWAP PUT 
                    END »
            NEXT
            T N + 'T' STO
        END 
        "Extracting..." 1 DISP  
        2 X ^ 'H' 1
        T r - 0 FOR i
                   i 2 DISP
                   DO UNTIL GETI END
        -1 STEP  1 - GET EXP * CEIL
        1240 .2 BEEP CLMF » »
DISP were mainly for debugging and later for speed optimization.

Where HRAZ is :
Code:
HRAZ:
«        2 LN 'L2' STO        3 LN 'L3' STO      5 LN 'L5' STO
      L2 L3 / 'LA' STO     L2 L5 / 'LB' STO   L3 L5 / 'LC' STO
             0 'X" STO           1  'N' STO         1  'T' STO
 { 30 } -1 CON 'E' STO {1250} 0 CON  'H' STO  »
I used global variables to keep a trace of what happened after each run. Don't know if that speed-up the computations or not ? Having all these variables local will make the 'user menu' much clearer.


On HP-48/50g, faster algorithms may certainly exist storing 'H' as a list in order to take advantage of the built-in SORT instruction that may certainly spare run time.

Such an instruction is missing on the HP-28s, to avoid sorting, I use a kind of rudimentary (but huge) hash-table; all 'H' values are in the range ] -1 ; 0 ], and relative order is kept for any slide 'X' ; no sorting require, just have to count non null value to extract the result !

Regards.
C.Ret
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming puzzle: Longest list of regular numbers? - C.Ret - 01-17-2021 09:02 PM



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