Post Reply 
RPL second impressions (HP 28)
06-29-2018, 01:08 PM
Post: #17
RE: RPL second impressions (HP 28)
(06-28-2018 09:43 PM)Thomas Klemm Wrote:  But similar functions exist e.g. on the WP-34S:
  • PRIME?
  • NEXTP

You can't really know that the initial number is a prime if you only have NEXTP.
Thus you need PRIME? at least for the first check:
PRIME?
NEXTP
NEXTP
NEXTP
(...)

Here is a simple PRIME? implementation for the HP-28S:

« DUP 2 / FP
  IF NOT NOT
  THEN DUP √ 1
    DO 2 + 3 DUPN
SWAP OVER
    UNTIL < ROT ROT
MOD NOT OR
    END SWAP DROP
MOD NOT
  END NOT
»


It will work for n > 1 ( 1 is NOT prime).

That's one of my first RPL programs (HP-28S, back in 1987), so it can surely be optimized a bit.

Gerson.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RPL second impressions (HP 28) - mdunn - 06-27-2018, 01:19 AM
RE: RPL second impressions (HP 28) - mdunn - 06-27-2018, 01:58 PM
RE: RPL second impressions (HP 28) - mdunn - 06-27-2018, 04:06 PM
RE: RPL second impressions (HP 28) - mdunn - 06-27-2018, 05:11 PM
RE: RPL second impressions (HP 28) - mdunn - 06-27-2018, 07:45 PM
RE: RPL second impressions (HP 28) - mdunn - 06-28-2018, 08:48 PM
RE: RPL second impressions (HP 28) - Gerson W. Barbosa - 06-29-2018 01:08 PM
RE: RPL second impressions (HP 28) - ttw - 07-04-2018, 10:52 PM



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