Friday, January 13, 2012

January 13, 2012--Triskaidekaphile

Friday the 13ths are Rona's favorite days.

Yesterday, on the 12th, while walking along the beach, I thought--Wouldn't be nice for me to be able to calculate when Friday the 13ths will occur. That way I could tell her she had one to look forward to on ____ and then after that on ____ .

I realized this would be complicated. There are only twelve thirteens per year and 52 Fridays. Then there is the complication of the months being of different lengths; and, making matters worse. there are those darned Leap Years. How then to determine when Friday the 13ths will occur?

I'm not smart enough to figure this out on my own so I turned to the Internet.

Of the methods I found there, here's my favorite algorithm:

Assume year is known and is an integer.

Loop from 1 to 12

Create date with loop index, year and 13 for the day

Determine day of week as per established algorithms

If day of week calculated above is Friday, do your work

If you want to start with a month and year (you have to assume some sort of year), your algorithm becomes

Assume year is known and an integer

Assume month is known and is an integer

Loop

Create date with index of loop as year, known month variable, and 13 for the day

Determine day of week as per established algorithms

If day of week calculate above is Friday, return date, or else

Increment year by 1


Got it?

If like Rona you have Triskaidekaphile, to save you the effort, the next Friday the 13ths are set for April and June of this year and then September and December, 2013.

They are not that rare, but are something to look forward to.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home