aboutsummaryrefslogtreecommitdiff
path: root/challenge-019
diff options
context:
space:
mode:
authorSteven Wilson <steven1170@zoho.eu>2019-07-30 15:50:00 +0100
committerSteven Wilson <steven1170@zoho.eu>2019-07-30 15:50:00 +0100
commit9a13a2fc0c93d4ff5de959e4f3b4abf0bec1c7f7 (patch)
treefe87ea81756acf6e35f731569508a1cbbcf3f444 /challenge-019
parent145f59407ae78145d6d16d05cb6039ca05e11f44 (diff)
downloadperlweeklychallenge-club-9a13a2fc0c93d4ff5de959e4f3b4abf0bec1c7f7.tar.gz
perlweeklychallenge-club-9a13a2fc0c93d4ff5de959e4f3b4abf0bec1c7f7.tar.bz2
perlweeklychallenge-club-9a13a2fc0c93d4ff5de959e4f3b4abf0bec1c7f7.zip
add solution to week 19 task 1
Diffstat (limited to 'challenge-019')
-rw-r--r--challenge-019/steven-wilson/perl5/ch-1.pl30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-019/steven-wilson/perl5/ch-1.pl b/challenge-019/steven-wilson/perl5/ch-1.pl
new file mode 100644
index 0000000000..1433da3bd7
--- /dev/null
+++ b/challenge-019/steven-wilson/perl5/ch-1.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+# Author: Steven Wilson
+# Date: 2019-07-30
+# Week: 019
+#
+# 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 DateTime;
+use feature qw/ say /;
+
+# If there are 31 days in a month and the first day of the month is a Friday
+# then there are 5 weekends in a month.
+
+my $dt = DateTime->new(
+ year => 1900,
+ month => 1,
+ day => 1,
+);
+
+while ( $dt->year() < 2020 ) {
+ if ( $dt->month_length() == 31 && $dt->dow() == 5 ) {
+ say $dt->year() . " " . $dt->month_name();
+ }
+ $dt->add( months => 1 );
+}
+