Post Reply 
HHC 2014 Programming Contest
10-05-2014, 10:02 AM (This post was last modified: 10-05-2014 11:11 AM by C.Ret.)
Post: #34
RE: HHC 2014 Programming Contest
The version proposed by Werner inspires me and I produce the following codes on my poor HP-28S.
Code:
HHC2014:
« { -8769  131 228 331 430 531 630 731 831 930 1031 1130 1231 } 
  IF OVER LEAP? THEN 3 229 PUT END 
  SWAP 1E4 * → Lst y0
  « { } y0 1 +
    1 13 FOR i
       i 13 < 100 8900 IFTE +
       IF y0 Lst i GET + PRIME?
         THEN IF DUP PRIME? THEN SWAP OVER + SWAP END END
    NEXT DROP » »
The last DROP instruction is facultative; it's only clean up stack to only return the list of PDP.

As there is no native ISPRIME?, ISLEAP? or calendar functions on HP28S/C, I have to propose one homebrew version:
Code:
LEAP?:
« DUP    4 MOD 
  OVER 100 MOD NOT 
  ROT  400 MOD AND OR NOT »
This Leap Year tester is directly inspired from the version published by Werner/Christian Meland (but adapted to HP28S/C specific environment)
Code:
PRIME?:
« → p
  « 2 WHILE DUP SQ p ≤ 1 FC? AND
           REPEAT 
             IF p OVER MOD
             THEN NXTODD 
             ELSE 1 SF END END
    SIGN FC?C » »
Of course, the following propose PRIME? is not really fast. A better strategy has to be adopted here to reduce time need for testing as large integer as 20141231 or 99991231.
But this may be the subject of another MPO challenge that will spare batteries!

Code:
NXTODD:
«  DUP 2 MOD + 1 + »
Please note that NXTODD is store as an independent program to facilitate reading (and a potential evolution of the code). It may advantageously change into any NEXTPRIME function.

Also, flag 1 have to be clear before the first use of PRIME? (this spare a 1 CF at the beginning of the program) But have any importance only at first use, since the last instruction clear flag 1 whatever the result (cf. FC?C )
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HHC 2014 Programming Contest - Paul Dale - 09-24-2014, 09:13 AM
RE: HHC 2014 Programming Contest - BruceH - 10-02-2014, 09:35 PM
RE: HHC 2014 Programming Contest - Jeff O. - 09-29-2014, 01:41 PM
RE: HHC 2014 Programming Contest - Jeff O. - 09-30-2014, 04:39 PM
RE: HHC 2014 Programming Contest - Jeff O. - 10-06-2014, 05:01 PM
RE: HHC 2014 Programming Contest - Jeff O. - 10-07-2014, 12:26 PM
RE: HHC 2014 Programming Contest - Werner - 10-03-2014, 07:35 AM
RE: HHC 2014 Programming Contest - C.Ret - 10-05-2014 10:02 AM
RE: HHC 2014 Programming Contest - Werner - 10-05-2014, 08:02 PM



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