RPL exercise  Last Digits of Primes (HP 49G, G+, 50g)

06012019, 02:38 PM
Post: #10




RE: RPL exercise  Last Digits of Primes (HP 49G, G+, 50g)
.
Hi, Carsen, (06012019 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 nonnegative 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 HP71B code using that approach but this challenge is for RPL machines and I don't want to intrude. Regards and have a nice weekend. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection 

« Next Oldest  Next Newest »

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