Post Reply 
RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-01-2019, 08:51 AM
Post: #7
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
Hi Everyone.

Here's my take on the challenge. The algorithm is very straightforward. Get the next prime number, put it in a string, retrieve the last digit in the string, test if the digit is a 1, 3, 7, 9, or none of the above, & then add it to the list.

Code:

<<   { 0 0 0 0 }  5 ROT 1 SWAP
START NEXTPRIME DUP ->STR DUP
SIZE DUP SUB STR->
CASE DUP 1 ==
THEN { 1 0 0 0 }
END DUP 3 ==
THEN { 0 1 0 0 }
END DUP 7 ==
THEN { 0 0 1 0 }
END DUP 9 ==
THEN { 0 0 0 1 }
END DUP ==
THEN { 0 0 0 0 }
END
END NIP ROT ADD SWAP NEXT DROP
>>

Not great performance in Exact mode, hitting 151.9 seconds with 1000 primes starting with 7. However, in Approx. mode, I get a decent time of 86.5 seconds.

Thanks for the challenge Gerson. I had fun.
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) - Carsen - 06-01-2019 08:51 AM



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