aboutsummaryrefslogtreecommitdiff
path: root/challenge-103/abigail/python/ch-1.py
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2021-03-15 18:18:09 +0800
committer冯昶 <seaker@qq.com>2021-03-15 18:18:09 +0800
commit5ed25077fde85262036c9db3e893d70ae0907b5c (patch)
tree8932d25b3fa6076e2d91ab2a331d4d8bfff20544 /challenge-103/abigail/python/ch-1.py
parent8b6be37fe4dac8b4c6489a95e55514b76b298d15 (diff)
parent65d54d52500028ec5359a7d39619803ade281543 (diff)
downloadperlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.tar.gz
perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.tar.bz2
perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-103/abigail/python/ch-1.py')
-rw-r--r--challenge-103/abigail/python/ch-1.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-103/abigail/python/ch-1.py b/challenge-103/abigail/python/ch-1.py
new file mode 100644
index 0000000000..ebe2362239
--- /dev/null
+++ b/challenge-103/abigail/python/ch-1.py
@@ -0,0 +1,45 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as python ch-1.py < 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.
+#
+
+yin_yang = ["Yang", "Yin"]
+heavenly_stems = ["Metal", "Metal", "Water", "Water", "Wood", "Wood",
+ "Fire", "Fire", "Earth", "Earth"]
+earthly_branches = ["Monkey", "Rooster", "Dog", "Pig", "Rat", "Ox",
+ "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat"]
+
+
+import fileinput
+
+for year in fileinput . input ():
+ year = int (year)
+ print (yin_yang [year % len (yin_yang)],
+ heavenly_stems [year % len (heavenly_stems)],
+ earthly_branches [year % len (earthly_branches)])