Oct 22, 2010

5 Weekends

Seems like a lot of people are excited that this month has 5 Fridays, Saturdays and Sundays. They say that it hasn't happened in <some large number> of years (every time I see it, the number is different).

Except, you know, January of this year. Or May last year. So, fail.

Maybe they all meant that there hasn't been any Octobers with 5 Fridays, Saturdays and Sundays (FSSs) in that many years. My answer: go go gadget Ruby! Here's a little script that will find the last October which had 5 FSSs:
i = 2009
# a month with 31 days will have 5 FSSs iff the first
# day of the month is a Friday
begin
  day = Date.parse("#{i}-10-01")
  i -= 1
end until day.wday == 5

puts day.year
Turns out the answer is....2004! Sure enough looking at the calendar for October 2004 it does indeed have 5 FSSs. Before that? 1999. Before that? 1993. I could go on but I'm getting bored of this.

4 comments:

Paddy3118 said...

It seems that your post inspired this: http://rosettacode.org/wiki/Five_weekends

Thanks!

Rob Britton said...

Oh damn! I love Rosetta Code, I suppose I should have thought of putting that up as a problem... oh well. I put up a Ruby version :)

Michael Mol said...

Well, yeah. This blog's in my blogroll, and it isn't the first time I've stolen a task idea from you. I mentioned the post in the IRC channel, and Mwn3d put it together. :)

Anonymous said...

I'm surprised anyone would fall for that. Which day of the week a date falls on follows an easy to work out path. The day of the week a date will fall on advances one day a year for each year, except leap years when it advances two days*. Given this, it's easy to see that we'd expect the pattern you note, with 5 or 6 years between occurrences(Depending exactly how the leap years fall in the cycle). A rarer thing would actually be when there is a longer than 6 year gap between 5 weekend October years(which day is skipped on leap year follows a 5-day pattern, so it will hit all the days eventually, so you just need to wait 8*4 years for it to skip the same day). As far as I can tell, that should only happen ever 32 years or so.

*how do we know this:
365%7= 1
366%7= 2
or you might have just noticed it like I did when I was like 10.