Chinese zodiac: Difference between revisions

m
no edit summary
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
mNo edit summary
 
(26 intermediate revisions by 13 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 simultaneouslists of cycleslabels, one of length 10 (the "celestial" stems(or "heavenly") "stems" – and one of length 12 (the "terrestrial" branches(or "earthly"); the"branches". combinationThe resultslabels indo anot repeatingreally 60-yearhave pattern.any Mappingmeaning theoutside branchestheir topositions twelvein traditionalthe animaltwo deitieslists; resultsthey're insimply thea well-knowntraditional "Chineseenumeration zodiac"device, assigningused eachmuch yearas toWesterners ause givenletters animaland numbers. ForThey example,were Tuesday,historically Februaryused 1,for 2022months CEand (indays theas commonwell Gregorianas calendar)years, will beginand the lunisolarstems Yearare ofstill thesometimes used for school Tigergrades.
 
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 name pair occurs only once.
The celestial stems have no one-to-one mapping like that of the branches to animals; however, the five pairs of consecutive stems each belong to one of the five traditional Chinese elements (Wood, Fire, Earth, Metal, and Water). Further, one of the two years within each element's governance is associated with <i>yin</i>, the other with <i>yang</i>.
 
Mapping the branches to twelve traditional animal deities results in the well-known "Chinese zodiac", assigning each year to a given animal. For example, Saturday, February 10, 2024 CE (in the common Gregorian calendar) began the lunisolar Year of the Dragon.
Thus, 2022 is also the yang year of Water. Note that since 12 is an even number, the association between animals and yin/yang doesn't change. Consecutive Years of the Rooster will cycle through the five elements, but will always be yin, despite the apparent conceptual mismatch between the specifically-male English animal name and the female aspect denoted by yin.
 
The 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 traditional <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 2024 CE is also the yang year of Wood. Since 12 is an even number, the association between animals and yin/yang aspect doesn't change; consecutive Years of the Dragon will cycle through the five elements, but will always be yang.
 
;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 13 ⟶ 17:
;Requisite information:
* The animal cycle runs in this order: Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig.
* 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 yang year precedes the yin year within each element.
* The currentfirst 60-year cycle(Wood beganRat, inyang) 1984 CE;of the firstcurrent 60-year cycle of the Common Era began in 41984 CE.
 
Thus,The 1984 was thelunisolar year ofbeginning thein Wood2024 Rat (yang), 1985 was the year of the Wood Ox (yin), and 1986 the year of the Fire Tiger (yang); 2022CE - which, as already noted, is the year of the WaterWood TigerDragon (yang) - is the 39th year41st of the current cycle.
 
;Information for optional task:
Line 23 ⟶ 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 20222024 is '''壬寅甲辰''' (''rénjĭa-yínchén'' or ren2jia3-yin2chen2).
=={{header|11l}}==
{{trans|C++}}
Line 381 ⟶ 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 679 ⟶ 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 760 ⟶ 811:
2017 Fire Rooster Yin
</pre>
=={{header|BASIC256BASIC}}==
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">
# Chinese zodiac
Line 797 ⟶ 849:
2017: 丁酉 (dīng-yŏu, Fire Rooster; Yin - ciclo 34/60)
</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">100 rem Chinese zodiac
110 cls
120 dim animals$(12)
130 for i = 0 to ubound(animals$)-1 : read animals$(i) : next i
140 dim elements$(5)
150 for i = 0 to ubound(elements$)-1 : read elements$(i) : next i
160 dim yinyang$(2)
170 yinyang$(0) = "Yang" : yinyang$(1) = "Yin"
180 dim years(7)
190 for i = 0 to ubound(years)-1 : read years(i) : next i
200 for i = 0 to ubound(years)-1
210 xyear = years(i)
220 yelement$ = elements$(((xyear-4) mod 10)/2)
230 yanimal$ = animals$((xyear-4) mod 12)
240 yyinyang$ = yinyang$(xyear mod 2)
250 nn = ((xyear-4) mod 60)+1
260 print xyear "is the year of the " yelement$ " " yanimal$ " (" yyinyang$ ")."
270 next i
280 end
290 data "Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig"
300 data "Wood","Fire","Earth","Metal","Water"
310 data 1935,1938,1968,1972,1976,1984,2017</syntaxhighlight>
{{out}}
<pre>Same as Yabasic entry.</pre>
 
==={{header|GW-BASIC}}===
The [[#MSX_BASIC|MSX BASIC]] solution works without any changes.
 
==={{header|MSX Basic}}===
{{works with|Chipmunk Basic}}
{{works with|GW-BASIC}}
{{works with|PC-BASIC}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">100 REM Chinese zodiac
110 CLS
120 PRINT " **** Chinese zodiac ****"
130 DIM animals$(12)
140 FOR i = 0 TO 11
150 READ animals$(i)
160 NEXT i
170 DIM elements$(5)
180 FOR i = 0 TO 4
190 READ elements$(i)
200 NEXT i
210 DIM yinyang$(2)
220 yinyang$(0) = "Yang"
230 yinyang$(1) = "Yin"
240 DIM years(7)
250 FOR i = 0 TO 6
260 READ years(i)
270 NEXT i
280 FOR i = 0 TO 6
290 xyear = years(i)
300 yelement$ = elements$(((xyear-4) MOD 10)/2)
310 yanimal$ = animals$((xyear-4) MOD 12)
320 yyinyang$ = yinyang$(xyear MOD 2)
330 nn = ((xyear-4) MOD 60)+1
340 PRINT xyear; "is the year of the "; yelement$; " "; yanimal$; " ("; yyinyang$; ")."
350 NEXT i
360 END
370 DATA "Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig"
380 DATA "Wood","Fire","Earth","Metal","Water"
390 DATA 1935,1938,1968,1972,1976,1984,2017</syntaxhighlight>
{{Out}}
https://www.dropbox.com/s/ckhu3u5pbwq7p5n/Chinese_zodiac%20%28MSX%29.png?dl=0
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "Zodiac.bas"
110 STRING ANIMALS$(0 TO 11)*7,ELEMENTS$(0 TO 4)*5,YINYANG$(0 TO 1)*4
120 FOR I=0 TO 11
130 READ ANIMALS$(I)
140 NEXT
150 FOR I=0 TO 4
160 READ ELEMENTS$(I)
170 NEXT
180 LET YINYANG$(0)="Yang":LET YINYANG$(1)="Yin"
190 CALL ZODIAC(1935):CALL ZODIAC(1938)
200 CALL ZODIAC(1968):CALL ZODIAC(1972)
210 CALL ZODIAC(1976):CALL ZODIAC(2017)
220 DEF ZODIAC(YEAR)
230 LET YELEMENT$=ELEMENTS$(MOD((YEAR-4),10)/2)
240 LET YANIMAL$=ANIMALS$(MOD((YEAR-4),12))
250 LET YYINYANG$=YINYANG$(MOD(YEAR,2))
260 PRINT YEAR;"is the year of the ";YELEMENT$;" ";YANIMAL$;" (";YYINYANG$;")."
270 END DEF
280 DATA Rat,Ox,Tiger,Rabbit,Dragon,Snake, Horse,Goat,Monkey,Rooster,Dog,Pig
290 DATA Wood,Fire,Earth,Metal,Water</syntaxhighlight>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{works with|Chipmunk Basic}}
{{works with|GW-BASIC}}
{{works with|MSX_BASIC}}
{{works with|PC-BASIC}}
<syntaxhighlight lang="qbasic">10 REM Chinese zodiac
20 CLS
30 DIM animals$(12)
40 DIM elements$(5)
50 DIM yinyang$(2)
70 FOR i = 0 TO 11
80 READ animals$(i)
90 NEXT i
110 FOR i = 0 TO 4
120 READ elements$(i)
130 NEXT i
140 yinyang$(0) = "Yang": yinyang$(1) = "Yin"
150 DIM years(7)
170 FOR i = 0 TO 6
180 READ years(i)
190 NEXT i
200 FOR i = 0 TO 6
210 xyear = years(i)
220 yelement$ = elements$(((xyear - 4) MOD 10) / 2)
230 yanimal$ = animals$((xyear - 4) MOD 12)
240 yyinyang$ = yinyang$(xyear MOD 2)
250 nn = ((xyear - 4) MOD 60) + 1
260 PRINT xyear; "is the year of the "; yelement$; " "; yanimal$; " ("; yyinyang$; ")."
270 NEXT i
280 END
290 DATA "Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig"
300 DATA "Wood","Fire","Earth","Metal","Water"
310 DATA 1935,1938,1968,1972,1976,1984,2017</syntaxhighlight>
{{out}}
<pre>Same as Yabasic entry.</pre>
 
=={{header|Befunge}}==
 
Line 992 ⟶ 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,066 ⟶ 1,247:
{{Out}}
https://i.imgur.com/f3Fo1xm.png
 
=={{header|Common Lisp}}==
{{trans|Ruby}}
Line 1,226 ⟶ 1,408:
dīngyŏu huǒ jī yīn
34/60 fire rooster </pre>
 
=={{header|Dart}}==
<syntaxhighlight lang="dart">Set animals = {'Rat','Ox','Tiger','Rabbit','Dragon','Snake','Horse','Goat','Monkey','Rooster','Dog','Pig'};
Set elements = {'Wood', 'Fire', 'Earth', 'Metal', 'Water'};
 
String getElement(num year) {
num element = ((year - 4) % 10 / 2);
return elements.elementAt(element.floor());
}
 
String getAnimal(int year) {
return animals.elementAt((year - 4) % 12);
}
 
String getYY(int year) {
return (year % 2 == 0) ? 'Yang' : 'Yin';
}
 
void main() {
Set years = {1935, 1938, 1968, 1972, 1976, 2017};
//the zodiac cycle didnt start until 4 CE, so years <4 shouldnt be valid
for (int i = 0; i < 6; i++) {
int indice = years.elementAt(i);
print('$indice is the year of the ${getElement(indice)} ${getAnimal(indice)} (${getYY(indice)}).');
}
}</syntaxhighlight>
{{out}}
<pre>Same as Yabasic entry.</pre>
 
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
Line 1,330 ⟶ 1,541:
1985 is the year of the Wood Ox (yin). 乙丑
2017 is the year of the Fire Rooster (yin). 丁酉</pre>
=={{header|EasyLang}}==
<syntaxhighlight>
animal$[] = [ "Rat" "Ox" "Tiger" "Rabbit" "Dragon" "Snake" "Horse" "Goat" "Monkey" "Rooster" "Dog" "Pig" ]
element$[] = [ "Wood" "Fire" "Earth" "Metal" "Water" ]
yingyang$[] = [ "Yang" "Yin" ]
animal_ch$[] = strchars "子丑寅卯辰巳午未申酉戌亥"
stem_ch$[] = strchars "甲乙丙丁戊己庚辛壬癸"
#
proc get year . el$ an$ yy$ anch$ stch$ .
idx = (year - 4) mod 10
el$ = element$[idx div 2 + 1]
stch$ = stem_ch$[idx + 1]
idx = (year - 4) mod 12
an$ = animal$[idx + 1]
anch$ = animal_ch$[idx + 1]
yy$ = yingyang$[year mod 2 + 1]
.
proc zodiac year . .
get year el$ an$ yy$ anch$ stch$
print year
cycle = (year - 1983) mod1 60
print " " & el$ & " " & an$ & " " & yy$ & " " & cycle & "/60"
print " " & stch$ & anch$
print ""
.
zodiac 1935
zodiac 1938
zodiac 1968
zodiac 1972
zodiac 1976
zodiac 1984
zodiac 2017
</syntaxhighlight>
 
 
=={{header|Excel}}==
===LAMBDA===
Line 1,734 ⟶ 1,980:
| style="text-align:center" | bright
|}
 
=={{header|F Sharp|F#}}==
<syntaxhighlight lang="fsharp">
Line 1,812 ⟶ 2,059:
2017 is the year of the Fire Rooster (yin).
</pre>
=={{header|Forth}}==
{{works with|gforth|0.7.3}}
 
<syntaxhighlight lang="forth">
: position ( n -- n ) 4 - 60 mod ;
 
s" Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey RoosterDog Pig "
drop constant animals
: animal ( n -- a u ) 12 mod 7 * animals + 7 -trailing ;
 
s" Wood Fire EarthMetalWater" drop constant elements
: element ( n -- a u ) 2/ 5 mod 5 * elements + 5 -trailing ;
 
s" yangyin " drop constant aspects
: aspect ( n -- a u ) 2 mod 4 * aspects + 4 -trailing ;
 
next-arg s>number? drop d>s position
dup element type space
dup animal type space
aspect '(' emit type ')' emit cr
bye
</syntaxhighlight>
 
{{out}}
<pre>
; for (x in 1935 1938 1968 1972 1976 1984 2017) {printf '%s ' $x; gforth zodiac.f $x}
1935 Wood Pig (yin)
1938 Earth Tiger (yang)
1968 Earth Monkey (yang)
1972 Water Rat (yang)
1976 Fire Dragon (yang)
1984 Wood Rat (yang)
2017 Fire Rooster (yin)
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">dim as string yy(0 to 1) = {"yang", "yin"}
Line 1,841 ⟶ 2,123:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Chinese_zodiac}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
 
[[File:Fōrmulæ - Chinese zodiac 01.png]]
 
'''Test case'''
 
[[File:Fōrmulæ - Chinese zodiac 02.png]]
 
[[File:Fōrmulæ - Chinese zodiac 03.png]]
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
In '''[https://formulae.org/?example=Chinese_zodiac this]''' page you can see the program(s) related to this task and their results.
=={{header|Go}}==
<syntaxhighlight lang="go">package main
Line 2,355 ⟶ 2,644:
rényín shuǐ hǔ yáng
39/60 water tiger </pre>
=={{header|jq}}==
'''Works with jq and gojq, that is, the C and Go implementations of jq.'''
 
'''Adapted from [[#Wren|Wren]]'''
<syntaxhighlight lang=jq>
def ChineseZodiac: {
animals : ["Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
"Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"],
aspects : ["Yang","Yin"],
elements : ["Wood", "Fire", "Earth", "Metal", "Water"],
stems : ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"],
branches : ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"],
sNames : ["jiă", "yĭ", "bĭng", "dīng", "wù", "jĭ", "gēng", "xīn", "rén", "gŭi"],
bNames : ["zĭ", "chŏu", "yín", "măo", "chén", "sì", "wŭ", "wèi", "shēn", "yŏu", "xū", "hài"]
};
 
def ChineseZodiac($year):
($year - 4) as $y
| ($y % 10) as $s
| ($y % 12) as $b
| ChineseZodiac
| { year : $year,
stem : .stems[$s],
branch : .branches[$b],
sName : .sNames[$s],
bName : .bNames[$b],
element : .elements[($s/2)|floor],
animal : .animals[$b],
aspect : .aspects[$s % 2],
cycle : ($y % 60 + 1)
};
 
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
# Input: ChineseZodiac($year)
def toString:
(.sName + "-" + .bName | lpad(9)) as $name
| (.element|lpad(7)) as $elem
| (.animal|lpad(7)) as $anim
| (.aspect|lpad(6)) as $aspt
| ((.cycle|lpad(2)) + "/60") as $cycl
| "\(.year) \(.stem)\(.branch) \($name) \($elem) \($anim) \($aspt) \($cycl)" ;
 
 
"Year Chinese Pinyin Element Animal Aspect Cycle",
"---- ------- --------- ------- ------- ------ -----",
(ChineseZodiac(1935, 1938, 1968, 1972, 1976, 1984, 2017, 2020) | toString)
</syntaxhighlight>
{{output}}
<pre>
Year Chinese Pinyin Element Animal Aspect Cycle
---- ------- --------- ------- ------- ------ -----
1935 乙亥 yĭ-hài Wood Pig Yin 12/60
1938 戊寅 wù-yín Earth Tiger Yang 15/60
1968 戊申 wù-shēn Earth Monkey Yang 45/60
1972 壬子 rén-zĭ Water Rat Yang 49/60
1976 丙辰 bĭng-chén Fire Dragon Yang 53/60
1984 甲子 jiă-zĭ Wood Rat Yang 1/60
2017 丁酉 dīng-yŏu Fire Rooster Yin 34/60
2020 庚子 gēng-zĭ Metal Rat Yang 37/60
</pre>
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
Line 2,425 ⟶ 2,776:
1976: 丙辰 (bĭng-chén, Fire Dragon; yang - year 53 of the cycle)
2018: 戊戌 (wù-xū, Earth Dog; yang - year 35 of the cycle)</pre>
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.1.2
Line 3,513 ⟶ 3,865:
|dark
|}
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ dup echo
say " is the year of the "
4 - dup 10 mod 2 /
[ table $ "Wood" $ "Fire" $ "Earth"
$ "Metal" $ "Water" ]
do echo$
sp
dup 12 mod
[ table
$ "Rat" $ "Ox" $ "Tiger" $ "Rabbit"
$ "Dragon" $ "Snake" $ "Horse" $ "Goat"
$ "Monkey" $ "Rooster" $ "Dog" $ "Pig" ]
do echo$
say " ("
2 mod
[ table $ "yang" $ "yin" ]
do echo$
say ")." cr ] is zodiac ( $ --> )
 
' [ 1935 1938 1968 1972 1976 1984 1985 2017 ]
witheach zodiac</syntaxhighlight>
 
{{out}}
 
<pre>1935 is the year of the Wood Pig (yin).
1938 is the year of the Earth Tiger (yang).
1968 is the year of the Earth Monkey (yang).
1972 is the year of the Water Rat (yang).
1976 is the year of the Fire Dragon (yang).
1984 is the year of the Wood Rat (yang).
1985 is the year of the Wood Ox (yin).
2017 is the year of the Fire Rooster (yin).
</pre>
 
=={{header|Racket}}==
{{trans|Common Lisp}}
Line 3,640 ⟶ 4,029:
76543 is the year of the Water Rabbit (yin).
</pre>
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
≪ 4 -
{ "Wood " "Fire " "Earth " "Metal " "Water " }
OVER 10 MOD 1 + 2 / GET
{ "Rat" "Ox" "Tiger" "Rabbit" "Dragon" "Snake" "Horse" "Goat" "Monkey" "Rooster" "Dog" "Pig" }
3 PICK 12 MOD 1 + GET +
SWAP 2 MOD " (yin)" " (yang)" IFTE +
≫ ''''CHZOD'''' STO
 
2022 '''CHZOD'''
{{out}}
<pre>
1: "Water Tiger (yang)"
</pre>
 
=={{header|Ruby}}==
This is written as a command-line tool that takes a list of CE year numbers as arguments and outputs their information; if no arguments are supplied, it displays the information for the current year.
Line 3,720 ⟶ 4,125:
Given no arguments and run during the year 2017:
<pre>丁酉 (dīng-yŏu, Fire Rooster; yin - year 34 of the cycle)</pre>
 
=={{header|Rust}}==
{{trans|Kotlin}}
Line 4,014 ⟶ 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,054 ⟶ 4,459:
0 OK, 0:1047
</pre>
 
=={{header|UNIX Shell}}==
{{works with|Bash|4+}}
Line 4,364 ⟶ 4,770:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
class ChineseZodiac {
Line 4,422 ⟶ 4,828:
2020 庚子 gēng-zĭ Metal Rat Yang 37/60
</pre>
 
=={{header|XPL0}}==
{{trans|C}}
<syntaxhighlight lang "XPL0">include xpllib; \for Print
 
int Animals, Elements;
 
func GetElement(Year);
int Year, Element;
[Element:= rem((Year-4)/10) / 2;
return Elements(Element);
];
 
func GetAnimal(Year);
int Year;
return Animals(rem((Year-4)/12));
 
func GetYY(Year);
int Year;
if rem(Year/2) = 0 then return "yang"
else return "yin";
 
int Year, Years, I;
[Years:= [ 1935, 1938, 1968, 1972, 1976, 2017 ];
Animals:= [ "Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig" ];
Elements:= [ "Wood","Fire","Earth","Metal","Water" ];
for I:= 0 to 6-1 do
[Year:= Years(I);
Print("%d is the year of the %s %s (%s).\n", Year, GetElement(Year), GetAnimal(Year), GetYY(Year));
]
]</syntaxhighlight>
{{out}}
<pre>
1935 is the year of the Wood Pig (yin).
1938 is the year of the Earth Tiger (yang).
1968 is the year of the Earth Monkey (yang).
1972 is the year of the Water Rat (yang).
1976 is the year of the Fire Dragon (yang).
2017 is the year of the Fire Rooster (yin).
</pre>
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">
1,479

edits