Post Reply 
RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-01-2019, 02:38 PM
Post: #10
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
.
Hi, Carsen,

(06-01-2019 08:51 AM)Carsen Wrote:  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 [...]

That's too inefficient, you don't need to deal with strings to extract the last digit of a non-negative integer number, just do a MOD 10, which will be much simpler and many times faster.

Also, once you have the last digit you don't need to do any comparisons, just use that last digit as the index to elements in an array which holds the counts for each last digit and keep a tally by simply incrementing the corresponding array element having that index (the last digit).

I'd post one line of trivial HP-71B code using that approach but this challenge is for RPL machines and I don't want to intrude. Smile

Regards and have a nice weekend.

V.
.

  
Find All My HP-related Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website 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) - Valentin Albillo - 06-01-2019 02:38 PM



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