diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-07-29 14:55:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-29 14:55:24 +0100 |
| commit | 4c13b5080f6f7649d9305c9528d96ef2bf22c0b7 (patch) | |
| tree | 1ea22b63543c37e39f369ca18d0d2961a8fa93e9 /challenge-019 | |
| parent | 2c0f4c13284dee279c6b1eb96fc70676fb648771 (diff) | |
| parent | 5890fbc9ce9a9832ec5e55f1c6bd8e871d017991 (diff) | |
| download | perlweeklychallenge-club-4c13b5080f6f7649d9305c9528d96ef2bf22c0b7.tar.gz perlweeklychallenge-club-4c13b5080f6f7649d9305c9528d96ef2bf22c0b7.tar.bz2 perlweeklychallenge-club-4c13b5080f6f7649d9305c9528d96ef2bf22c0b7.zip | |
Merge pull request #444 from Scimon/master
Months with 5 weekends in
Diffstat (limited to 'challenge-019')
| -rw-r--r-- | challenge-019/simon-proctor/perl6/ch-1.p6 | 26 |
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; +} |
