From 5890fbc9ce9a9832ec5e55f1c6bd8e871d017991 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 29 Jul 2019 14:23:53 +0100 Subject: Months with 5 weekends in --- challenge-019/simon-proctor/perl6/ch-1.p6 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 challenge-019/simon-proctor/perl6/ch-1.p6 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; +} -- cgit