RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-01-2019, 11:05 PM (This post was last modified: 06-01-2019 11:06 PM by Dave Britten.)
Post: #17
 Dave Britten Senior Member Posts: 2,312 Joined: Dec 2013
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
I don't have my 48 handy at the moment, but here's a 42S/DM42 version. Input the number of primes greater than 5 to look for, and XEQ "PRMDGT". The number of primes ending in 1, 3, 7, and 9 will be in stack T, Z, Y, and X respectively. This uses the well-known mod 30 sieve to check for primes.

Code:
00 { 53-Byte Prgm } 01▸LBL "PRMDGT" 02 CLRG 03 STO 06 04 5 05 STO 05 06▸LBL 00 07 2 08 STO+ 05 09▸LBL 01 10 RCL 05 11 XEQ "PRIME?" 12 FC? 01 13 GTO 00 14 RCL 05 15 10 16 MOD 17 1 18 STO+ IND ST Y 19 DSE 06 20 GTO 00 21 RCL 01 22 RCL 03 23 RCL 07 24 RCL 09 25 CF 01 26 END 00 { 96-Byte Prgm } 01▸LBL "PRIME?" 02 STO 00 03 SF 01 04 0 05 STO 02 06 2 07 XEQ 02 08 1 09 XEQ 02 10 2 11 XEQ 02 12 2 13 XEQ 02 14▸LBL 01 15 RCL 00 16 RCL 02 17 X↑2 18 X>Y? 19 RTN 20 4 21 XEQ 02 22 2 23 XEQ 02 24 4 25 XEQ 02 26 2 27 XEQ 02 28 4 29 XEQ 02 30 6 31 XEQ 02 32 2 33 XEQ 02 34 6 35 XEQ 02 36 GTO 01 37▸LBL 02 38 STO+ 02 39 RCL 00 40 RCL 02 41 X=Y? 42 RTN 43 MOD 44 X=0? 45 CF 01 46 RTN 47 END

This finds and tallies 1000 primes in about 25 seconds on my DM42 when running in fast mode (i.e. connected to external power).
 « 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