aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Proctor <simon.proctor@zpg.co.uk>2019-07-29 14:23:53 +0100
committerSimon Proctor <simon.proctor@zpg.co.uk>2019-07-29 14:23:53 +0100
commit5890fbc9ce9a9832ec5e55f1c6bd8e871d017991 (patch)
tree8a600449da7046452918ec426db13c8fd5199955
parentf309b17f1652cb9911793d5aad3cf68369769719 (diff)
downloadperlweeklychallenge-club-5890fbc9ce9a9832ec5e55f1c6bd8e871d017991.tar.gz
perlweeklychallenge-club-5890fbc9ce9a9832ec5e55f1c6bd8e871d017991.tar.bz2
perlweeklychallenge-club-5890fbc9ce9a9832ec5e55f1c6bd8e871d017991.zip
Months with 5 weekends in
-rw-r--r--challenge-019/simon-proctor/perl6/ch-1.p626
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-019/simon-proctor/perl6/ch-1.p6 b/challenge-019/simon-proctor/perl6/ch-1.p6
new file mode 100644
index 0000000000..d7456d0a97
--- /dev/null
+++ b/challenge-019/simon-proctor/perl6/ch-1.p6
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+#| Given a starting an ending year print all months in the years between (inclusive) with 5 weekends (Friday, Saturday and Sunday)
+multi sub MAIN(
+ Int() $start = 1900, #= Starting year. Defaults to 1900
+ Int() $end = Date.today().year() #= Ending year. Default to this year.
+) {
+ say "Months with 5 Fridays between {$start} and {$end}";
+
+ for $start..$end -> $year {
+ for 1..12 -> $month {
+ my $range = Date.new( :$year, :$month, :1day )..Date.new( :$year, :$month, day => Date.new( :$year, :$month ).days-in-month );
+ my @weekends = (5..7).map( -> $dow { $range.grep( *.day-of-week == $dow ).elems } );
+ say "{$year}-{sprintf("%02d",$month)}" if all( @weekends ) == 5;
+ }
+ }
+}
+
+#| Display help text
+multi sub MAIN(
+ Bool :h(:$help) where ?*
+) {
+ say $*USAGE;
+}