The Artima Developer Community
Sponsored Link

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

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Andy Lester

Posts: 514
Nickname: petdance
Registered: Jun, 2009

Andy Lester is an author and programmer.
Debunking the "five weekends every 823 years" myth with Perl Posted: Mar 20, 2013 11:29 AM
Reply to this message Reply

This post originated from an RSS feed registered with Perl Buzz by Andy Lester.
Original Post: Debunking the "five weekends every 823 years" myth with Perl
Feed Title: Perlbuzz
Feed URL: http://perlbuzz.com/atom.xml
Feed Description: What's happening in the world of Perl programming, including Perl 5, Perl 6, the CPAN and Parrot?
Latest Perl Buzz Posts
Latest Perl Buzz Posts by Andy Lester
Latest Posts From Perlbuzz

Advertisement

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.

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

Topic: Perlbuzz news roundup for 2013-04-01 Previous Topic   Next Topic Topic: Perlbuzz news roundup for 2013-03-18


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us