Debunking the "five weekends every 823 years" myth with Perl

This year, July has five Fridays, five Saturdays and five Sundays. This happens once every 823 years. So: copy to your status and money will arrive within 4 days... based on Chinese Feng Shui.

Of course it's crap, and of course Snopes.com does a fine job of debunking it. But what if you want more evidence? Perl to the rescue! Here's a little program that finds and counts all the months with five full Fri-Sun weekends in the next 823 years.

#!/usr/bin/perl
# Debunking the five weekends myth
# http://www.snopes.com/inboxer/trivia/fivedays.asp
use strict;
use warnings;
use feature 'say';
use DateTime;
my $start = 2013;
my $end = $start + 823 - 1;
say "Months with five full weekends between $start and $end";
my $nmonths = 0;
for my $year ( $start .. $end ) {
for my $month ( 1..12 ) {
my $eom = DateTime->last_day_of_month(
year => $year, month => $month );
if ( $eom->day == 31 && $eom->day_of_week == 7 ) {
say $eom->month_name, ' ', $year;
++$nmonths;
}
}
}
say "There will be $nmonths months with five full
weekends in the 823 years between $start and $end.";
$ ./five-weekends
Months with five full weekends between 2013 and 2835
March 2013
August 2014
May 2015
...
October 2832
July 2833
December 2834
There will be 823 months with five full weekends in the
823 years between 2013 and 2835.

Leave a comment

Land the Tech Job You Love, Andy Lester's
guide to job hunting for programmers and other technical professionals, is available
in PDF, ePub and .mobi formats, all DRM-free, as well as good old-fashioned paper.