Post Reply 
RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-01-2019, 05:44 AM
Post: #6
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
(06-01-2019 05:02 AM)DavidM Wrote:  
(06-01-2019 04:43 AM)Gerson W. Barbosa Wrote:  Yes, 155.4 seconds (base 10), or 155.4 ms per prime, but that’s not linear. For 100 primes it takes 7.38 seconds or about 13.5 primes per second. Anyway, that’s an improvement over my first attempt. Hopefully there’s still a better way.

Here's a fairly brute-force method:

Code:
\<<
   0. 9. NDUPN \->ARRY
   5
   ROT
   1 SWAP START
      NEXTPRIME
      SWAP OVER
      I\->R 10. MOD
      DUP2
      GET 1. + PUT
      SWAP
   NEXT
   DROP
   DUP 1. GET SWAP
   DUP 3. GET SWAP
   DUP 7. GET SWAP
   9. GET
   4. \->LIST
\>>

The result for an input of 1000. is { 245. 253. 256. 246. }, and on my 50g takes about 41s to complete. Note that I'm using approximate numbers here instead of exact to shorten the time a bit.

Very nice!

53.3 seconds even using exact numbers. '155.4/41' = 3.79, this ratio used to be about 10 (that is, my programs used to take 10 times as much, compared to the optimal ones by Valentin and others).

I’ve used a somewhat unorthodox method which surely doesn’t obey the “KISS” rule. Also, my program is about 50% longer.
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 05:44 AM



User(s) browsing this thread: