aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoelle Maslak <jmaslak@antelope.net>2019-08-04 13:26:26 -0600
committerJoelle Maslak <jmaslak@antelope.net>2019-08-04 13:26:26 -0600
commit152e62ab49632f34b9b8f642fe893d80115922bb (patch)
tree23a6c563173de1d519cdf875faed8b3a42f61cab
parenta933b2dc940659b62cac2f180df777a90d16ac60 (diff)
downloadperlweeklychallenge-club-152e62ab49632f34b9b8f642fe893d80115922bb.tar.gz
perlweeklychallenge-club-152e62ab49632f34b9b8f642fe893d80115922bb.tar.bz2
perlweeklychallenge-club-152e62ab49632f34b9b8f642fe893d80115922bb.zip
Solution to 19.1 in P5 and P6
-rwxr-xr-xchallenge-019/joelle-maslak/perl5/ch-1.pl32
-rwxr-xr-xchallenge-019/joelle-maslak/perl6/ch-1.p629
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;
+ }
+ }
+}
+
+