aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-03-08 17:41:56 +0100
committerAbigail <abigail@abigail.be>2021-03-14 19:59:45 +0100
commitf9160aab6e21549aa9e99e9197ffcb6a3c82f1e4 (patch)
tree9733e522fc020f1019617c6c713228f8d45c5ca7
parent73981bf58f2136d524c5b2a4ad1015411e61faf5 (diff)
downloadperlweeklychallenge-club-f9160aab6e21549aa9e99e9197ffcb6a3c82f1e4.tar.gz
perlweeklychallenge-club-f9160aab6e21549aa9e99e9197ffcb6a3c82f1e4.tar.bz2
perlweeklychallenge-club-f9160aab6e21549aa9e99e9197ffcb6a3c82f1e4.zip
Perl solution for week 103, part 1
-rw-r--r--challenge-103/abigail/perl/ch-1.pl51
1 files changed, 51 insertions, 0 deletions
diff --git a/challenge-103/abigail/perl/ch-1.pl b/challenge-103/abigail/perl/ch-1.pl
new file mode 100644
index 0000000000..b73716a80c
--- /dev/null
+++ b/challenge-103/abigail/perl/ch-1.pl
@@ -0,0 +1,51 @@
+#!/opt/perl/bin/perl
+
+use 5.032;
+
+use strict;
+use warnings;
+no warnings 'syntax';
+
+use experimental 'signatures';
+use experimental 'lexical_subs';
+
+#
+# See ../README.md
+#
+
+#
+# Run as: perl ch-1.pl < input-file
+#
+# We're reading years from standard input, one year per line, outputting
+# years from the sexagenary cycle [1]. This is slightly more than what
+# the challenge ask; the challenge asks to output the heavenly stem [2],
+# and the earthly branch [3]. But we also output its Yin/Yang.
+#
+# [1] https://en.wikipedia.org/wiki/Sexagenary_cycle
+# [2] https://en.wikipedia.org/wiki/Heavenly_Stems
+# [3] https://en.wikipedia.org/wiki/Earthly_Branches
+#
+
+#
+# Each of the cycles have been rotated so the first entry corresponds to
+# the year 0 in the Proleptic Gregorian calendar. (We're using the
+# convention of having a year 0, as per ISO 8601).
+# That way, we can just mod the year with the number of entries, without
+# first having to subtract something from the year.
+#
+# The heavenly stems last for 2 years, so we just duplicate the entries.
+#
+
+my $yin_yang = [qw [Yang Yin]];
+my $heavenly_stems = [map {($_) x 2} qw [Metal Water Wood Fire Earth]];
+my $earthly_branches = [qw [Monkey Rooster Dog Pig Rat Ox
+ Tiger Rabbit Dragon Snake Horse Goat]];
+
+
+while (my $year = <>) {
+ $, = " ";
+ say map {$$_ [$year % @$_]} $yin_yang, $heavenly_stems, $earthly_branches;
+}
+
+
+__END__