aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoelle Maslak <jmaslak@antelope.net>2019-06-17 11:18:53 -0600
committerJoelle Maslak <jmaslak@antelope.net>2019-06-17 11:18:53 -0600
commitda063ef93df95c9d59b9cbbd0a2dfa8bbc2aaf42 (patch)
tree53c52560d43aaf77d7a7cba6e519b7ee4339ce97
parent9253a13f5320a27c6ab063dc3c3c6343b4020c97 (diff)
downloadperlweeklychallenge-club-da063ef93df95c9d59b9cbbd0a2dfa8bbc2aaf42.tar.gz
perlweeklychallenge-club-da063ef93df95c9d59b9cbbd0a2dfa8bbc2aaf42.tar.bz2
perlweeklychallenge-club-da063ef93df95c9d59b9cbbd0a2dfa8bbc2aaf42.zip
Perl 5 solution to 13.1
-rwxr-xr-xchallenge-013/joelle-maslak/perl5/ch-1.pl44
1 files changed, 44 insertions, 0 deletions
diff --git a/challenge-013/joelle-maslak/perl5/ch-1.pl b/challenge-013/joelle-maslak/perl5/ch-1.pl
new file mode 100755
index 0000000000..76ec1f3a29
--- /dev/null
+++ b/challenge-013/joelle-maslak/perl5/ch-1.pl
@@ -0,0 +1,44 @@
+#!/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);
+
+die("Must provide year") if @ARGV != 1;
+my $year = +$ARGV[0];
+
+my $days = get_all_days($year);
+say join "\n",
+ map { strftime("%Y-%m-%d", gmtime($_)) }
+ grep { last_friday($_) }
+ @$days;
+
+sub last_friday($dt) {
+ if ((gmtime($dt))[6] == 5) { # Is day Friday?
+ # Is this the LAST friday? Add a week to it and see if the
+ # month changes
+ if ((gmtime($dt+(86400*7)))[4] != (gmtime($dt))[4]) {
+ return 1;
+ }
+ }
+ return;
+}
+
+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;
+}
+