Post Reply 
RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-03-2019, 03:49 AM
Post: #24
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
(06-01-2019 12:48 PM)grsbanks Wrote:  
(06-01-2019 08:51 AM)Carsen Wrote:  ...test if the digit is a 1, 3, 7, 9, or none of the above
How could it be none of the above?

Oops. Smile You're right. A simple impetuous mistake on my part.

(06-01-2019 02:38 PM)Valentin Albillo Wrote:  
(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).

Okay. That makes a lot of sense, especially after I single stepped (SST) through DavidM's first RPL program that he posted in this thread because he did exactly what you described Valentin. After reflecting other's variants of code, this exercise will remind me how useful the MOD function can be in programming because I never really use it.

(06-01-2019 03:17 PM)Gerson W. Barbosa Wrote:  Just two remarks:

1) The STR-> before should be an OBJ-> (just a manual listing mistake);

2) You can omit the optional case clause, DUP == THEN { 0 0 0 0 } END (see grsbanks's comment below in this thread). Thus your byte count will be under 200 and you can save about three seconds in Exact Mode.

Nice! Save 3 seconds in Exact mode! I sure like that.
I have a question on remark 1 Gerson. Why should my STR-> be replaced with an OBJ->?

Thanks everyone!
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-03-2019 03:49 AM

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