Post Reply 
RPL mini-challenge - Triangle of Primes (HP-49G/G+,50g)
07-01-2019, 09:45 PM
Post: #14
RE: RPL mini-challenge - Triangle of Primes (HP-49G/G+,50g)
(07-01-2019 05:20 PM)Gerson W. Barbosa Wrote:  My newer 50g (CNA2240GYB) is slightly slower than yours: 402.76 seconds for k=99. My program is a bit slower as well: 409.17 seconds.

Your program might be slower but sure it's more clever!
I ran it in newRPL just for kicks: 108 bytes (had to make slight modifications for newRPL, won't comment here to avoid spoiling the answer to others).
Your code runs 99 in 176 msec under newRPL.

By the way, at 108 bytes you also take the title of newRPL Champion too. That's because I realized my solution does not work properly for an input of 0, so I'm disqualifying myself :-).
I re-coded the challenge so it works properly but it grew up to 136 bytes (from 96 bytes), on the other hand it now does 99 in 134 msec.

Code:



**** Anti - Spoiler ****













Here's my rework that meets the original requirements:
«
  2 * 'M' LSTO 2 DUP 'K'
  LSTO WHILE K M ≤ REPEAT
    DUP 1 K START
      NEXTPRIME 
    NEXT
    K 2 + 'K' STO 
  END
  M 2 / 1 + →LIST 
»


And this is Gerson's code ported to newRPL:
«
  { } 1 0 DUP 5 ROLL START
    1 OVER START
      UNROT NEXTPRIME
      ROT 
    NEXT
    UNROT DUP UNROT ADD
    SWAP ROT 2 + 
  NEXT
  DROP2 
»

Here " + LASTARG NIP" was replaced with "DUP UNROT ADD SWAP", because newRPL does not support LASTARG, also + and ADD have swapped their functionality. It adds 4 bytes (1 command) in size to his original solution.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: RPL mini-challenge - Triangle of Primes (HP-49G/G+,50g) - Claudio L. - 07-01-2019 09:45 PM



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