Post Reply 
HHC 2014 Programming Contest
09-27-2014, 06:50 PM (This post was last modified: 09-27-2014 06:52 PM by Don Shepherd.)
Post: #17
RE: HHC 2014 Programming Contest
(09-27-2014 04:47 PM)Neil Hamilton Wrote:  I gave this a shot in RPL. First attempt yielded 70 s/yr on a 49G+, not too good. This scanned EVERY day of the year (some twice!). Fairly brain dead...

I realized that I could increment by 2 if the first candidate was odd, unless the day of the month was in danger of rolling over to a new month, so pegged this limit at > 27 to make February happy. This got it down to 60 s/yr.

Cleaned up a bunch of duplication and it dropped to 23 s/yr. Getting better.

Then I realized that the ONLY PDPs occurred when the months changed over (eg: 31 Mar - 1 Apr). So I only needed to make 7 (+1) sets of tests per year on the 31st of one month and the 1st of the next, and adding in poor February by subtracting 1 from 1 Mar to see if it is a leap year or not. The months were encoded into a list {1 3 5 7 8 10 12} and this list was processed using FOR and GET with dates being synthesized from the entered year, the day of 31 and the month extracted from the list, and then used searched for PDPs. The February issue was executed after the main list processing loop so PDPs found here could be displayed out of sequence. This got me down to just under 1 s/yr such that I ran the set of years from 1593 - 2014 in 430 s (432 yrs) which detected 58 PDPs. Running from 1800 - 2014 I got 14 PDPs in 113.3 s.

I will run 1583 - 9999 at work on my 50G plugged into USB so I don't destroy my batteries. I estimate that will take ~8400 s and should yields about 1122 +/- 50 PDPs.

The program is still a bit large at 401.5 bytes but I can likely drop it some. I am currently printing out more that the required minimum, for example.

Has the definitive list of PDPs been released?

Was there a ruling on a PDP anchoured to 31 Dec spilling into 1 Jan of the next year (cannot recall if I found any)? Technically that would not be in a single calendar year: "(and only in that year)".

(Pauli, my eldest is haunting Brisbane for the next week or so. For someone who is nervous of heights, he did the Sydney Bridge walk. Not something I would choose to do.)


Neil, I thought the problem included only generating the list of PDPs for a specific given year: you input a year, and the program tells you the PDPs for that year (max of 7, of course). So the length of time the program runs is governed largely by the routine to determine if a number is prime. If that takes 10 seconds for a given number, for example, then the whole program (7 iterations max) would take less than 70 seconds since the factors of several of those numbers would be found rather quickly.
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 - Don Shepherd - 09-27-2014 06:50 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)