March 2013 Archives

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

| 1 Comment

Have you seen this bit of bunk posted recently? It goes like this:

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.

Perlbuzz news roundup for 2013-03-18

| No Comments

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

perl101.org needs a new maintainer

| No Comments

A few years back, I started perl101.org as a website that I could point newbies at for simple explanations of how to do basic tasks. I found the same questions getting asked over and over on StackOverflow, so I figured I'd aggregate the common answers together. It's the same reason I put together bobby-tables.com to explain SQL injection and htmlparsing.com to explain how to parse HTML without regular expressions.

However, for the past couple of years I haven't touched it, and I'd like it if someone who would actually maintain it, like I haven't, would take it over, domain name, hosting and all. If this sounds like something you'd be interested in, drop me an email.

Perlbuzz news roundup for 2013-03-11

| No Comments

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

« February 2013 | Main Index | Archives | April 2013 »