Chinese zodiac: Difference between revisions
m
no edit summary
(→{{header|APL}}: Add implementation.) |
mNo edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1:
{{task}}Determine the Chinese zodiac sign and related associations for a given year.
Years cycle through both lists concurrently, so that both stem and branch advance each year; if we used Roman letters for the stems and numbers for the branches, consecutive years would be labeled A1, B2, C3, etc. Since the two lists are different lengths, they cycle back to their beginning at different points: after J10 we get A11, and then after B12 we get C1. However, since both lists are of even length, only like-parity pairs occur (A1, A3, A5, but not A2, A4, A6), so only half of the 120 possible pairs are included in the sequence. The result is a repeating 60-year pattern within which each
Mapping the branches to twelve traditional animal deities results in the well-known "Chinese zodiac", assigning each year to a given animal. For example,
The
Thus, the Chinese year beginning in
;Task: Create a subroutine or program that will return or output the animal, yin/yang association, and element for the lunisolar year that begins in a given CE year.
Line 19:
* The element cycle runs in this order: Wood, Fire, Earth, Metal, Water.
* Each element gets two consecutive years; a yang followed by a yin.
* The
;Information for optional task:
Line 27:
* The twelve terrestrial branches are '''子''' ''zĭ'', '''丑''' ''chŏu'', '''寅''' ''yín'', '''卯''' ''măo'', '''辰''' ''chén'', '''巳''' ''sì'', '''午''' ''wŭ'', '''未''' ''wèi'', '''申''' ''shēn'', '''酉''' ''yŏu'', '''戌''' ''xū'', '''亥''' ''hài''. In ASCII Pinyin, those are "zi3", "chou3", "yin2", "mao3", "chen2", "si4", "wu3", "wei4", "shen1", "you3", "xu1", and "hai4".
Therefore 1984 was '''甲子''' (''jiă-zĭ'', or jia3-zi3)
=={{header|11l}}==
{{trans|C++}}
Line 413:
cs ← celestial year
tb ← terrestrial year
vec ← year, (position year), cs, tb, (pinyinFor cs), (pinyinFor tb), (element year), (animal year), (aspect year)
∇
10 1 ⍴ cz ¨ 1935 1938 1941 1944 1947 1968 1972 1976 2003 2006</syntaxhighlight>
{{Out}}
<pre>
1947 24 丁亥 dīng hài Fire Pig yin
1972 49 壬子 rén zĭ Water Rat yang
2006 23 丙戌 bĭng xū Fire Dog yang
</pre>
Line 1,171 ⟶ 1,173:
</pre>
=={{header|Commodore BASIC}}==
{{works with|Commodore 64
<syntaxhighlight lang="basic">1000 rem display the chinese zodiac for a given year
1010 poke 53281,7: rem yellow background
Line 1,245 ⟶ 1,247:
{{Out}}
https://i.imgur.com/f3Fo1xm.png
=={{header|Common Lisp}}==
{{trans|Ruby}}
|