HHC 2014 Programming Contest
10-05-2014, 08:02 PM (This post was last modified: 10-05-2014 08:13 PM by Werner.)
Post: #35
 Werner Senior Member Posts: 525 Joined: Dec 2013
RE: HHC 2014 Programming Contest
JHM's routine should work if you replace the IFTs by their IF THEN END counterparts:
(untested)

Code:
\<<   \<< IF DUP2 MOD NOT THEN          IF DUP2 > THEN DROP2 -1 2 END          END   \>>   \-> p   \<< 1 MAX 2 p EVAL 1 + p EVAL 2 + p EVAL 2 +       WHILE DUP2 SQ \>= REPEAT           p EVAL 4 + p EVAL 2 + p EVAL 4 + p EVAL       2 + p EVAL 4 + p EVAL 6 + p EVAL 2 + p EVAL 6 +       END DROP 1 >    \>> \>>

Remark that I changed the ultimate test to 1 >
This way it will work for 0 and 1, too. I edited my previous post as well.

Or else, my own simple concoction.
Code:
\<<   1 MAX 2   IF DUP2 MOD THEN 1 +   IF DUP2 MOD THEN 2 +   IF DUP2 MOD THEN 2 +    ELSE SWAP END   ELSE SWAP END   ELSE SWAP END   WHILE DUP2 SQ \>= REPEAT     IF DUP2 MOD THEN 4 +     IF DUP2 MOD THEN 2 +     IF DUP2 MOD THEN 4 +     IF DUP2 MOD THEN 2 +     IF DUP2 MOD THEN 4 +     IF DUP2 MOD THEN 6 +     IF DUP2 MOD THEN 2 +     IF DUP2 MOD THEN 6 +     ELSE SWAP END     ELSE SWAP END     ELSE SWAP END     ELSE SWAP END     ELSE SWAP END     ELSE SWAP END     ELSE SWAP END     ELSE SWAP END   END   \>= \>>

Yet, to speed up the PDP routine, consider the following:
If yyyymm01 is prime and the day before isn't, then we have performed a lengthy primality testing for nothing.
What we should have is a routine BOTHPRIME? that tests two numbers for divisibility by ever increasing factors at the same time - If both are prime, that will gain us nothing, but if one or both are not, then we will gain a lot of time. I think.
How many times does it happen that yyyymm01 is prime and the day before isn't?
To be continued..

Werner
 « Next Oldest | Next Newest »

 Messages In This Thread HHC 2014 Programming Contest - Paul Dale - 09-24-2014, 09:13 AM RE: HHC 2014 Programming Contest - Paul Dale - 09-24-2014, 09:31 AM RE: HHC 2014 Programming Contest - Paul Dale - 09-24-2014, 09:41 AM RE: HHC 2014 Programming Contest - Paul Dale - 09-24-2014, 11:46 AM RE: HHC 2014 Programming Contest - David Hayden - 09-24-2014, 12:46 PM RE: HHC 2014 Programming Contest - Paul Dale - 09-24-2014, 09:40 PM RE: HHC 2014 Programming Contest - Joe Horn - 09-24-2014, 03:18 PM RE: HHC 2014 Programming Contest - David Hayden - 09-25-2014, 12:48 AM RE: HHC 2014 Programming Contest - Paul Dale - 09-25-2014, 12:58 AM RE: HHC 2014 Programming Contest - BruceH - 10-02-2014, 09:35 PM RE: HHC 2014 Programming Contest - Paul Dale - 09-24-2014, 09:38 AM RE: HHC 2014 Programming Contest - David Hayden - 09-24-2014, 11:24 AM RE: HHC 2014 Programming Contest - Dave Britten - 09-24-2014, 01:39 PM RE: HHC 2014 Programming Contest - Don Shepherd - 09-24-2014, 01:46 PM RE: HHC 2014 Programming Contest - brouhaha - 09-25-2014, 06:12 AM RE: HHC 2014 Programming Contest - Paul Dale - 09-25-2014, 06:54 AM RE: HHC 2014 Programming Contest - Neil Hamilton - 09-27-2014, 04:47 PM RE: HHC 2014 Programming Contest - Don Shepherd - 09-27-2014, 06:50 PM RE: HHC 2014 Programming Contest - Joe Horn - 09-28-2014, 12:08 AM RE: HHC 2014 Programming Contest - David Hayden - 09-28-2014, 01:39 PM RE: HHC 2014 Programming Contest - Neil Hamilton - 09-29-2014, 11:13 AM RE: HHC 2014 Programming Contest - David Hayden - 09-29-2014, 11:35 AM RE: HHC 2014 Programming Contest - Neil Hamilton - 09-27-2014, 06:56 PM RE: HHC 2014 Programming Contest - Don Shepherd - 09-27-2014, 07:44 PM RE: HHC 2014 Programming Contest - Joe Horn - 09-28-2014, 12:16 AM RE: HHC 2014 Programming Contest - Neil Hamilton - 09-28-2014, 11:58 AM RE: HHC 2014 Programming Contest - Joe Horn - 09-29-2014, 12:43 PM RE: HHC 2014 Programming Contest - Jeff O. - 09-29-2014, 01:41 PM RE: HHC 2014 Programming Contest - Joe Horn - 09-30-2014, 01:20 AM 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 - Paul Dale - 10-06-2014, 09:34 PM RE: HHC 2014 Programming Contest - Jeff O. - 10-07-2014, 12:26 PM RE: HHC 2014 Programming Contest - Thomas Klemm - 09-29-2014, 04:57 PM RE: HHC 2014 Programming Contest - Neil Hamilton - 09-29-2014, 05:27 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)