Created
March 12, 2009 16:58
-
-
Save gugod/78165 to your computer and use it in GitHub Desktop.
Counting the number of black Fridays in years
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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