RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-01-2019, 09:59 PM
Post: #16
 Valentin Albillo Senior Member Posts: 1,100 Joined: Feb 2015
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)

Hi again, Gerson:

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

Please do it if you wish, that's no intrusion. I mentioned RPL and those particular models because they have ISPRIME built-in (not sure about the HP-71B or its Math ROM).

Ok, thanks. Since you asked for it, this is my HP-71B code. All the work is done by the one line in the middle (45 bytes), the first line is just initialization and the last line is just for outputting results and timing:

1   DESTROY ALL @ DIM T(9) @ INPUT N @ SETTIME 0 @ P=5
2   FOR I=1 TO N @ P=FPRIM(P+2) @ L=MOD(P,10) @ T(L)=T(L)+1 @ NEXT I
3   FOR I=1 TO 9 STEP 2 @ DISP T(I); @ NEXT I @ DISP TIME

As I told Carsen in my previous post above, there's no need for strings and there's no need for comparisons, cases, or whatever unneeded complexities, using the last digit as an index to increment that digit's count is all it takes to keep the tally. Running my code in go71b on an budget Android tablet I get this results and timings:

>RUN

? 100     ->   24, 26, 26, 24              in   0.07 sec.
? 1000    ->   245, 253, 256, 246          in   1.05 sec.
? 10000   ->   2485, 2515, 2508, 2492      in  18.21 sec.
? 100000  ->   24968, 25008, 25015, 25009  in 443.91 sec.

Best regards and have a nice weekend.

V.

All My Articles & other Materials here:  Valentin Albillo's HP Collection

 « 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: