aboutsummaryrefslogtreecommitdiff
path: root/challenge-103/abigail/bash
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-03-08 17:16:35 +0100
committerAbigail <abigail@abigail.be>2021-03-14 19:59:45 +0100
commit292e33319493e09adfee8f35a1b67b07e493e75a (patch)
treed3aab62448ccfd557d4cd5072d7d3effda69e31d /challenge-103/abigail/bash
parentf2f25420c71fd379993b2230bf9e8c239bb05297 (diff)
downloadperlweeklychallenge-club-292e33319493e09adfee8f35a1b67b07e493e75a.tar.gz
perlweeklychallenge-club-292e33319493e09adfee8f35a1b67b07e493e75a.tar.bz2
perlweeklychallenge-club-292e33319493e09adfee8f35a1b67b07e493e75a.zip
Bash solution for week 103, part 1
Diffstat (limited to 'challenge-103/abigail/bash')
-rw-r--r--challenge-103/abigail/bash/ch-1.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/challenge-103/abigail/bash/ch-1.sh b/challenge-103/abigail/bash/ch-1.sh
new file mode 100644
index 0000000000..1afcdf63d3
--- /dev/null
+++ b/challenge-103/abigail/bash/ch-1.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-1.sh < 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.
+#
+
+declare -a yin_yang
+declare -a heavenly_stems
+declare -a earthly_branches
+
+yin_yang=(Yang Yin)
+yin_yang_size=2
+heavenly_stems=(Metal Metal Water Water Wood Wood Fire Fire Earth Earth)
+heavenly_stems_size=10
+earthly_branches=(Monkey Rooster Dog Pig Rat Ox
+ Tiger Rabbit Dragon Snake Horse Goat)
+earthly_branches_size=12
+
+
+
+while read year
+do echo ${yin_yang[$((year % yin_yang_size))]} \
+ ${heavenly_stems[$((year % heavenly_stems_size))]} \
+ ${earthly_branches[$((year % earthly_branches_size))]}
+done