Chinese zodiac: Difference between revisions

m
no edit summary
m (→‎{{header|Wren}}: Minor tidy)
mNo edit summary
 
(8 intermediate revisions by 3 users not shown)
Line 1:
{{task}}Determine the Chinese zodiac sign and related associations for a given year.
 
Traditionally,In the Chinese have countedcalendar, years are identified using two lists of labels, one of length 10 (the "celestial" (or stems"heavenly") "stems" – and one of length 12 (the "terrestrial" (or branches"earthly") "branches". The labels do not really have any meaning outside their positions in the two lists; they're simply a traditional enumeration device, used much as Westerners use letters and numbers. They were historically used for months and days as well as years, and the stems are still sometimes used for school grades.
 
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 pairname of namespair occurs only once.
 
Mapping the branches to twelve traditional animal deities results in the well-known "Chinese zodiac", assigning each year to a given animal. For example, SundaySaturday, JanuaryFebruary 2210, 20232024 CE (in the common Gregorian calendar) began the lunisolar Year of the RabbitDragon.
 
The celestial stems do not have a one-to-one mapping like that of the branches to animals; however, the five <i>pairs</i> of consecutive stems are each associated with one of the five traditional Chinese<i>wǔxíng</i> elements (Wood, Fire, Earth, Metal, and Water). Further, one of the two years within each element is assigned to <i>yin</i>, the other to <i>yang</i>.
 
Thus, the Chinese year beginning in 20232024 CE is also the yinyang year of WaterWood. Since 12 is an even number, the association between animals and yin/yang aspect doesn't change; consecutive Years of the RabbitDragon will cycle through the five elements, but will always be yinyang.
 
;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 currentfirst 60-year cycle(Wood beganRat, inyang) 1984;of anythe multiple ofcurrent 60-year yearscycle frombegan thatin point may be used to reckon1984 fromCE.
 
Thus,The year 1 of a cycle is thelunisolar year ofbeginning thein Wood Rat (yang), year 2 the Wood Ox (yin), and year 3 the Fire Tiger (yang). The year2024 2023CE - which, as already noted, is the year of the WaterWood RabbitDragon (yinyang) - is the 40th year41st of the current cycle.
 
;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)., while 20232024 is '''癸卯甲辰''' (''gŭijĭa-măochén'' or gui3jia3-mao3chen2).
=={{header|11l}}==
{{trans|C++}}
Line 385:
2017 Fire Rooster Yin
</pre>
=={{header|APL}}==
{{works with|Dyalog APL}}
{{works with|GNU APL}}
 
This simply creates a vector of the attributes of the year.
 
<syntaxhighlight lang="apl">hanzi ← '甲' '乙' '丙' '丁' '戊' '己' '庚' '辛' '壬' '癸' '子' '丑' '寅' '卯' '辰' '巳' '午' '未' '申' '酉' '戌' '亥'
pinyin ← 'jiă' 'yĭ' 'bĭng' 'dīng' 'wù' 'jĭ' 'gēng' 'xīn' 'rén' 'gŭi' 'zĭ' 'chŏu' 'yín' 'măo' 'chén' 'sì' 'wŭ' 'wèi' 'shēn' 'yŏu' 'xū' 'hài'
 
pinyinFor ← { pinyin /⍨ ⍵ ⍷ hanzi }
 
stems ← '甲' '乙' '丙' '丁' '戊' '己' '庚' '辛' '壬' '癸'
branches ← '子' '丑' '寅' '卯' '辰' '巳' '午' '未' '申' '酉' '戌' '亥'
animals ← 'Rat' 'Ox' 'Tiger' 'Rabbit' 'Dragon' 'Snake' 'Horse' 'Goat' 'Monkey' 'Rooster' 'Dog' 'Pig'
elements ← 'Wood' 'Fire' 'Earth' 'Metal' 'Water'
aspects ← 'yang' 'yin'
 
position ← { 1 + 60 | ⍵ - 4 }
item ← { ⍺ ⌷⍨ 1 + (≢⍺) | 1 -⍨ position ⍵ }
celestial ← { stems item ⍵ }
terrestrial ← { branches item ⍵ }
animal ← { animals item ⍵ }
aspect ← { aspects item ⍵ }
element ← { elements ⌷⍨ 1+⌊2÷⍨1×⍨10 | 1 -⍨ position ⍵ }
 
∇vec ← cz year ; cs ; tb
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>
1935 12 乙亥 yĭ hài Wood Pig yin
1938 15 戊寅 wù yín Earth Tiger yang
1941 18 辛巳 xīn sì Metal Snake yin
1944 21 甲申 jiă shēn Wood Monkey yang
1947 24 丁亥 dīng hài Fire Pig yin
1968 45 戊申 wù shēn Earth Monkey yang
1972 49 壬子 rén zĭ Water Rat yang
1976 53 丙辰 bĭng chén Fire Dragon yang
2003 20 癸未 gŭi wèi Water Goat yin
2006 23 丙戌 bĭng xū Fire Dog yang
</pre>
 
=={{header|AppleScript}}==
{{Trans|JavaScript}}
Line 683 ⟶ 729:
dīngyŏu huǒ jī yīn
34/60 fire rooster </pre>
 
=={{header|AutoHotkey}}==
Chinese Animal/Element/Yin/Yang Characters Copied From "AppleScript"
Line 1,126 ⟶ 1,173:
</pre>
=={{header|Commodore BASIC}}==
{{works with|Commodore 64/128}}
<syntaxhighlight lang="basic">1000 rem display the chinese zodiac for a given year
1010 poke 53281,7: rem yellow background
Line 1,200 ⟶ 1,247:
{{Out}}
https://i.imgur.com/f3Fo1xm.png
 
=={{header|Common Lisp}}==
{{trans|Ruby}}
Line 2,079 ⟶ 2,127:
'''Solution'''
 
[[File:Fōrmulæ - Chinese zodiac 01a01.png]]
 
'''Test case'''
Line 2,085 ⟶ 2,133:
[[File:Fōrmulæ - Chinese zodiac 02.png]]
 
[[File:Fōrmulæ - Chinese zodiac 03a03.png]]
 
=={{header|Go}}==
Line 4,372 ⟶ 4,420:
dim @a(12) ' the animals
 
Push Dup("yang"), Dup("yin") ' fill Ying/Yang table
For i = 1 to 0 stepStep -1 : @y(i) = Pop() : Next i
' fill Elements table
Push Dup("Wood"), Dup("Fire"), Dup("Earth"), Dup("Metal"), Dup("Water")
For i = 4 to 0 stepStep -1 : @e(i) = Pop() : Next i
' fill Animals table
Push Dup("Rat"), Dup("Ox"), Dup("Tiger"), Dup( "Rabbit"), Dup( "Dragon"), "Snake"
Push Dup("SnakeHorse"), Dup("HorseGoat"), Dup("GoatMonkey"), "Rooster", Dup("MonkeyDog"), Dup( "RoosterPig")
Push Dup("Dog"), Dup("Pig")
 
For i = 11 to 0 step -1 : @a(i) = Pop() : Next i
Line 4,412 ⟶ 4,459:
0 OK, 0:1047
</pre>
 
=={{header|UNIX Shell}}==
{{works with|Bash|4+}}
1,479

edits