Post Reply 
RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-01-2019, 09:11 PM
Post: #15
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
(06-01-2019 04:08 PM)DavidM Wrote:  MOD with approximate numbers is generally faster than MOD with exact integers on the 50g, which is the main reason I used the old I→R 10. MOD construct in my original (and subsequent) programs.

That did the trick, thanks! By using 10. MOD R→I the running time fell down to 147.1 seconds (previously 1677.1 seconds!).

(06-01-2019 04:08 PM)DavidM Wrote:  Carsen's use of the case statement inspired me to take another look at the performance using that type of construct. I use case structures a lot in SysRPL, but tend not to in UserRPL because they always feel verbose in that environment for some reason. I made another stack-based attempt that uses a case structure for determining which counter to update:
Code:
\<<
   0. DUPDUP DUP
   5
   6. ROLL 1 SWAP START
      NEXTPRIME
      DUP I\->R 10. MOD
      CASE
         1. OVER SAME
         THEN
            DROP
            5. ROLL
            1. +
            5. ROLLD
         END

         3. OVER SAME
         THEN
            DROP
            4. ROLL
            1. +
            4. ROLLD
         END

         7. OVER SAME
         THEN
            DROP
            ROT
            1. +
            UNROT
         END

         DROP
         SWAP
         1. +
         SWAP
      END
   NEXT
   DROP
   4. \->LIST
\>>

While the code size jumped up considerably, the performance actually improved using this method by a few seconds (29s).

Wow! On my smartphone I get { 24968. 25008. 25015. 25009. } in 86 seconds and { 249934. 250109. 250017. 249940. } in about two and a half hours! Thanks again!
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-01-2019 09:11 PM



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