Skip to content

Instantly share code, notes, and snippets.

@gugod
Created March 12, 2009 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gugod/78165 to your computer and use it in GitHub Desktop.
Save gugod/78165 to your computer and use it in GitHub Desktop.
Counting the number of black Fridays in years
#!/usr/bin/env perl
use strict;
use warnings;
use feature ':5.10';
use DateTime;
use Text::Pluralize;
my @counts = ("");
for my $year (2000..12000) {
my @black_fridays;
for my $month (1..12) {
push @black_fridays, "$year-$month-13"
if DateTime->new(year => $year, month => $month, day => 13)->day_of_week == 5;
}
say pluralize(
"%d black Friday(s) in the year $year: @black_fridays",
@black_fridays
);
$counts[@black_fridays]++;
}
say "There are " . $counts[$_] ." $_-black-Friday years"
for 1..3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment