Skip to content

Instantly share code, notes, and snippets.

@davorg
Last active July 29, 2019 14:42
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 davorg/749925c2b57cf1aecf56b310cfda5f9f to your computer and use it in GitHub Desktop.
Save davorg/749925c2b57cf1aecf56b310cfda5f9f to your computer and use it in GitHub Desktop.
Perl Weekly Challenge #19 / Task #1
#!/usr/bin/perl
#
# Perl Weekly Challenge #19 / Task #1
#
# Write a script to display months from the year 1900 to 2019 where
# you find 5 weekends i.e. 5 Friday, 5 Saturday and 5 Sunday.
use strict;
use warnings;
use feature 'say';
use Time::Piece;
# A month can only have five weekends if:
#
# * It has 31 days
# * The 1st of the month is a Friday
# Array of months with 31 days
my @months = (qw[Jan Mar May Jul Aug Oct Dec]);
my $format = '%Y-%b';
for my $y (1900 .. 2019) {
for my $m (@months) {
# Get the first day of the month as a Time::Piece object
my $first = Time::Piece->strptime("$y-$m", $format);
# Print the date if the 1st is a Friday
say $first->strftime('%b %Y') if $first->day eq 'Fri';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment