diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-08-04 21:09:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-04 21:09:47 +0100 |
| commit | dd9658655ea707048039ccfd4d8965e7f5e83db1 (patch) | |
| tree | a164118f0e97192c12ec22197637fe2ab20f57a2 | |
| parent | ab1dabe064618f890f713c3ac76ddfc70bc0fdc3 (diff) | |
| parent | 152e62ab49632f34b9b8f642fe893d80115922bb (diff) | |
| download | perlweeklychallenge-club-dd9658655ea707048039ccfd4d8965e7f5e83db1.tar.gz perlweeklychallenge-club-dd9658655ea707048039ccfd4d8965e7f5e83db1.tar.bz2 perlweeklychallenge-club-dd9658655ea707048039ccfd4d8965e7f5e83db1.zip | |
Merge pull request #470 from jmaslak/joelle-19-1-1
Solution to 19.1 in P5 and P6
| -rwxr-xr-x | challenge-019/joelle-maslak/perl5/ch-1.pl | 32 | ||||
| -rwxr-xr-x | challenge-019/joelle-maslak/perl6/ch-1.p6 | 29 |
2 files changed, 61 insertions, 0 deletions
diff --git a/challenge-019/joelle-maslak/perl5/ch-1.pl b/challenge-019/joelle-maslak/perl5/ch-1.pl new file mode 100755 index 0000000000..35e12be63a --- /dev/null +++ b/challenge-019/joelle-maslak/perl5/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use v5.22; + +# Turn on method signatures +use feature 'signatures'; +no warnings 'experimental::signatures'; + +use POSIX qw(mktime strftime); + +my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); + +my (@days) = map { get_all_days($_)->@* } 1900..2019; +say join "\n", + map { $months[(gmtime($_))[4]] . " " . strftime("%Y", gmtime($_)) } + grep { (gmtime($_))[6] == 0 and (gmtime($_))[3] == 31 } + @days; + +sub get_all_days($year) { + my @ret; + my $day = mktime(0,0,12,1,0,$year-1900); + while ((gmtime($day))[5] == $year-1900) { + push @ret, $day; + $day += 86400; # Number of seconds in a day + } + + return \@ret; +} + diff --git a/challenge-019/joelle-maslak/perl6/ch-1.p6 b/challenge-019/joelle-maslak/perl6/ch-1.p6 new file mode 100755 index 0000000000..330788a6e6 --- /dev/null +++ b/challenge-019/joelle-maslak/perl6/ch-1.p6 @@ -0,0 +1,29 @@ +#!/usr/bin/env perl6 +use v6; + +# Shortcut: to have 5 weekends (including Friday), you need 31 days, and +# the 31st must fall on a Sunday. + +my @months = « + invalid + Jan Feb Mar Apr May Jun + Jul Aug Sep Oct Nov Dec +»; + +sub MAIN() { + my $days = (1900..2019).map( { get-all-days($_) } ).flat; + my $sunday31st = $days.grep( { $_.day-of-week == 7 and $_.day-of-month == 31 } ); + say $sunday31st.map( { @months[$_.month] ~ " " ~ $_.year } ).join("\n"); +} + +sub get-all-days(UInt:D $year) { + return gather { + state $dt = Date.new($year, 1, 1); + while $dt.year == $year { + take $dt; + $dt = $dt.succ; + } + } +} + + |
