Post Reply 
RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-01-2019, 09:59 PM
Post: #16
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. Smile

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.
 

  
Find All My HP-related Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website 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) - Valentin Albillo - 06-01-2019 09:59 PM



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