Post Reply 
RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-02-2019, 10:43 PM
Post: #21
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
(06-01-2019 09:59 PM)Valentin Albillo Wrote:   
 
Hi again, Gerson:

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

 

Hello, Valentin,

Thank you very much for the HP-71B version, much appreciated!
I’ve noticed, however, FPRIM() is not a standard HP-71B function. I assume it’s a LEX file, a Language EXtension file by what I can remember. So, my question – not addressed exclusively to you, but to whom else can answer it – is: what is the easiest way to implement it on the real HP-71B or at least on Emu71? Thanks in advance.

Best regards,

Gerson.
Find all posts by this user
Quote this message in a reply
06-02-2019, 11:27 PM
Post: #22
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
.
Hi, Gerson:

(06-02-2019 10:43 PM)Gerson W. Barbosa Wrote:  Thank you very much for the HP-71B version, much appreciated!

I’ve noticed, however, FPRIM() is not a standard HP-71B function. I assume it’s a LEX file, a Language EXtension file by what I can remember. So, my question – not addressed exclusively to you, but to whom else can answer it – is: what is the easiest way to implement it on the real HP-71B or at least on Emu71?

The easiest way to implement it on the real HP-71B or on Emu71 is by plugging in the JPC ROM, which is where the FPRIM keyword and dozens of others reside, and that is what I always do with my HP-71B, because an HP-71B it's not a "real" HP-71B but an emasculated one unless you fit it with a Math ROM, a JPC ROM and an HP-IL ROM. Oh, and a 128 Kb CMT RAM module, for good measure.

That's the power HP machine I use at all times and have been saying and advocating that much for the last 20+ years in this and the old forum, nothing new here.

Frankly, I don't quite see why RPL machines can use this or that library all the time without anyone raising an eyebrow (me included) and the moment I use a "library" (a ROM) with my HP-71B someone goes and asks what is "the easiest way to implement it on the real HP-71B".

Is my HP-71B unreal to you or what ?
I take it that you don't use any libraries with your RPL models, then ?

Best regards.
V.
.
Find all posts by this user
Quote this message in a reply
06-03-2019, 12:14 AM (This post was last modified: 06-03-2019 12:17 AM by Gerson W. Barbosa.)
Post: #23
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
(06-02-2019 11:27 PM)Valentin Albillo Wrote:  The easiest way to implement it on the real HP-71B or on Emu71 is by plugging in the JPC ROM, which is where the FPRIM keyword and dozens of others reside, and that is what I always do with my HP-71B, because an HP-71B it's not a "real" HP-71B but an emasculated one unless you fit it with a Math ROM, a JPC ROM and an HP-IL ROM. Oh, and a 128 Kb CMT RAM module, for good measure.

Here

✓ Math ROM
✗ JPC ROM
✓ HP-IL ROM
✓ 32 KB RAM

Plus card reader, HP-9114B disk-drive and proper floppies, IP-IL cables. JPC ROM still missing...

Best regards,

Gerson.
Find all posts by this user
Quote this message in a reply
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
06-03-2019, 04:25 AM
Post: #25
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
.
G'day, Gerson,

(06-03-2019 12:14 AM)Gerson W. Barbosa Wrote:  JPC ROM still missing...

Try this link: J-F Garnier's JPC ROM for the HP-71B.

There you'll find a treasure trove full of all kinds of manuals, guides, docs and of course binary images that you can immediately use with most any emulators such as Emu71 and even Android ones for your phone. I'm using Version F in both Win XP and Android.

I'm not fully sure but I think that someone described how to burn the image to a physical EPROM or whatever hardware, to use the JPC ROM in a physical HP-71B. Perhaps you'd want to try.

For the record, I used the amazing JPC ROM functionalities to help me solve about 100 Project Euler problems, it was highly entertaining to do that with such old software & hardware ! Smile

Best regards.
V.
.
Find all posts by this user
Quote this message in a reply
06-03-2019, 01:08 PM
Post: #26
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
(06-03-2019 03:49 AM)Carsen Wrote:  
(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->?

My mistake, sorry! It didn’t work for me because I picked ->STR from the menu instead of typing in STR->.
Find all posts by this user
Quote this message in a reply
06-03-2019, 08:15 PM
Post: #27
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
(06-03-2019 01:08 PM)Gerson W. Barbosa Wrote:  
(06-03-2019 03:49 AM)Carsen Wrote:  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->?

My mistake, sorry! It didn’t work for me because I picked ->STR from the menu instead of typing in STR->.

Lol.
Good thing you mentioned OBJ-> though. I somehow forgot OBJ-> parses strings. This must mean I haven't programmed my 50g enough recently Smile
Find all posts by this user
Quote this message in a reply
06-04-2019, 03:00 AM (This post was last modified: 06-04-2019 03:05 AM by Gerson W. Barbosa.)
Post: #28
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
(06-01-2019 03:07 AM)Gerson W. Barbosa Wrote:  Optionally, write a program that does the same for primes greater than 2 in base 8. In this case, the last digits are 1, 3, 5 and 7. 

  40 --> {7 12 11 10}

 120 --> {27 33 30 30}

1000 --> ?

  

Ok, that’s trivial from any of the base-10 programs. Anyway, for the sake of completeness, here is a 34-step program for the wp34s based on Dave Britten’s base-10 program for the DM42/HP-42S:

Code:

001 LBL A
002 STO A
003 CLx
004 FILL
005 STOS 01
006 STOS 05
007 # 001
008 TICKS
009 STO 02
010 LBL 00
011 R↓
012 INC X
013 INC X
014 PRIME?
015 XEQ 01
016 RCL 04
017 x<? A
018 GTO 00
019 TICKS
020 RCL- 02
021 STO 02
022 RCL 01
023 RCL 03
024 RCL 05
025 RCL 07
026 RTN
027 LBL 01
028 INC 04
029 RCL X
030 # 008
031 MOD
032 INC→X
033 R↓
034 END

1000 A -> 253
R↓ -> 254
R↓ -> 252
R↓ -> 241,

that is, 241 1’s, 252 3’s, 254 5’s and 253 7’s.

Running time in tenths of seconds in register 02:

RCL 02 -> 730 (low-battery condition)

or

RCL 02 -> 469 (USB-powered)
Find all posts by this user
Quote this message in a reply
06-04-2019, 02:21 PM (This post was last modified: 06-04-2019 02:37 PM by fred_76.)
Post: #29
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
Some interesting paper to understand the countings:

https://dms.umontreal.ca/~andrew/PDF/PrimeRace.pdf
Find all posts by this user
Quote this message in a reply
06-04-2019, 05:09 PM (This post was last modified: 06-04-2019 05:13 PM by ttw.)
Post: #30
RE: RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
Adding to Fred's suggested paper (which is really worth reading) is this Guy's paper.

https://www.ime.usp.br/~rbrito/docs/2322249.pdf

One of the examples: D. H. & Emma Lehmer discovered that 2^n=3 (mod n) for n = 4700063497, but for no smaller n > 1.
Find all posts by this user
Quote this message in a reply
Post Reply 




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