From e91dfe6e10f8192197ac5c81c8c82fafd1b377f6 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Mon, 29 Jul 2019 19:44:35 +0200 Subject: [019#1] --- 019/ch1.pl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 019/ch1.pl diff --git a/019/ch1.pl b/019/ch1.pl new file mode 100755 index 0000000..a3acb81 --- /dev/null +++ b/019/ch1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +# +# 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 DateTime; + +my @months; +for my $year (1900 .. 2019) { + for my $month (1 .. 12) { + my $date = DateTime->last_day_of_month(year => $year, month => $month); + my $day = $date->day; + my $dow = $date->day_of_week(); + push @months, $date->strftime("%m/%Y") + if $day == 30 && $dow == 7 || $day == 31 && ($dow == 7 || $dow == 1); + } +} + +print "Months with 5 weekends: @months\n" -- cgit v1.2.3