RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-03-2019, 03:49 AM
Post: #24
 Carsen Member Posts: 206 Joined: Jan 2017
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. 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!
 « Next Oldest | Next Newest »

 Messages In This Thread RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-01-2019, 03:07 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Valentin Albillo - 06-01-2019, 04:13 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-01-2019, 04:43 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - DavidM - 06-01-2019, 05:02 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gilles - 06-01-2019, 05:29 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Albert Chan - 06-01-2019, 12:42 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-01-2019, 05:44 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Carsen - 06-01-2019, 08:51 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - grsbanks - 06-01-2019, 12:48 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Valentin Albillo - 06-01-2019, 02:38 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-01-2019, 03:29 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Valentin Albillo - 06-01-2019, 09:59 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-02-2019, 10:43 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Valentin Albillo - 06-02-2019, 11:27 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-03-2019, 12:14 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Valentin Albillo - 06-03-2019, 04:25 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-01-2019, 03:17 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-01-2019, 03:41 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - DavidM - 06-01-2019, 04:08 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-01-2019, 09:11 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Dave Britten - 06-01-2019, 11:05 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-02-2019, 06:10 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - John Keith - 06-02-2019, 04:39 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gilles - 06-02-2019, 09:18 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Carsen - 06-03-2019 03:49 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-03-2019, 01:08 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Carsen - 06-03-2019, 08:15 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-04-2019, 03:00 AM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - fred_76 - 06-04-2019, 02:21 PM RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - ttw - 06-04-2019, 05:09 PM

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