Skip to content

Instantly share code, notes, and snippets.

@gustafe
Created January 8, 2023 20:03
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 gustafe/bfeaa83277e3f0355b6790fd70ca087f to your computer and use it in GitHub Desktop.
Save gustafe/bfeaa83277e3f0355b6790fd70ca087f to your computer and use it in GitHub Desktop.
Simple Perl program to count the number of month-day-weekday combinations since 1538 CE.
#! /usr/bin/env perl
use Modern::Perl '2015';
use DateTime;
###
use utf8;
binmode(STDOUT, ':encoding(UTF-8)');
my $date = DateTime->new(year=>1583 , month=>1 ,day=>1);
my $stats;
say "collating...";
while ($date <= DateTime->now()) {
push @{$stats->{$date->month}->{$date->day}->{$date->day_of_week}}, $date->\
year;
$date->add(days=>1);
say $date->ymd if ($date->year % 25 == 0 and $date->month==1 and $date->day\
==1);
}
say "printing...";
for my $month (sort {$a<=>$b} keys %{$stats}) {
for my $day (sort {$a<=>$b} keys %{$stats->{$month}}) {
printf "%02d-%02d: ",$month,$day;
for my $wday (sort {$a<=>$b} keys %{$stats->{$month}{$day}}) {
printf "%02d ", scalar @{$stats->{$month}{$day}{$wday}};
}
print "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment