Post Reply 
Find number property and write RPL program (HP-49G,G+, HP 50g)
09-24-2014, 08:04 PM
Post: #17
RE: Find number property and write RPL program (HP-49G,G+, HP 50g)
(09-24-2014 07:23 PM)Thomas Ritschel Wrote:  Of course, the first "ISPRIME?" isn't really necessary since all the primes are generated by using the "NEXTPRIME" command.

So here is a shorter and therefore faster version:
Code:
%%HP: T(3)A(R)F(.);
\<< \-> n
  \<< { } 0 2
    WHILE OVER n <
    REPEAT DUP 2 * 1 +
      IF ISPRIME?
      THEN SWAP 1 + SWAP ROT OVER + UNROT
      END
      NEXTPRIME
    END DROP2
  \>>
\>>

ISPRIME? { ... } IFT is less elegant than IF ISPRIME? THEN ... END, but saves you 5 bytes.
Nice there is no ELSE (IFTE) like mine.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Find number property and write RPL program (HP-49G,G+, HP 50g) - Gerson W. Barbosa - 09-24-2014 08:04 PM



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