Chinese zodiac: Difference between revisions

m
no edit summary
m (syntax highlighting fixup automation)
mNo edit summary
 
(28 intermediate revisions by 15 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++}}
 
<syntaxhighlight lang="11l">V animals = [‘Rat’, ‘Ox’, ‘Tiger’, ‘Rabbit’, ‘Dragon’, ‘Snake’, ‘Horse’, ‘Goat’, ‘Monkey’, ‘Rooster’, ‘Dog’, ‘Pig’]
V elements = [‘Wood’, ‘Fire’, ‘Earth’, ‘Metal’, ‘Water’]
 
Line 55 ⟶ 58:
2017 is the year of the Fire Rooster (yin).
</pre>
 
=={{header|360 Assembly}}==
{{trans|VBScript}}
<syntaxhighlight lang="text">* Chinese zodiac 10/03/2019
CHINEZOD CSECT
USING CHINEZOD,R13 base register
Line 135 ⟶ 137:
2017 is the year of the Fire Rooster (Yin ). 34/60
</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang=Action"action!">DEFINE PTR="CARD"
 
PTR ARRAY animals(12),elements(5),stems(10),branches(12),yinYangs(2)
Line 214 ⟶ 215:
2021 xin-chou Metal Ox Yin 38/60
</pre>
 
=={{header|Ada}}==
{{works with|GNAT|8.3.0}}
 
<syntaxhighlight lang=Ada"ada">
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
Line 348:
2017 is the year of Fire Rooster (yin). 丁酉
</pre>
 
=={{header|ALGOL 68}}==
{{Trans|AWK}}
<syntaxhighlight lang="algol68">BEGIN # Chinese Zodiac #
# returns s right-padded with blanks to w characters, or s if s is already at least w characters long #
PRIO PAD = 1;
Line 385 ⟶ 384:
1985 Wood Ox Yin
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>
 
Line 390 ⟶ 434:
{{Trans|JavaScript}}
{{Trans|Haskell}}
<syntaxhighlight lang=AppleScript"applescript">on run
-- TRADITIONAL STRINGS ---------------------------------------------------
Line 688 ⟶ 732:
=={{header|AutoHotkey}}==
Chinese Animal/Element/Yin/Yang Characters Copied From "AppleScript"
<syntaxhighlight lang=AutoHotkey"autohotkey">Chinese_zodiac(year){
Animal := StrSplit("Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Goat,Monkey,Rooster,Dog,Pig", ",")
AnimalCh := StrSplit("鼠牛虎兔龍蛇馬羊猴鸡狗豬")
Line 715 ⟶ 759:
return year "`t" S B " " Sn "-" Bn " `t" E " " Ec " " En "`t" A " " Ac " " An "`t" YY " " Yr
}</syntaxhighlight>
Examples:<syntaxhighlight lang=AutoHotkey"autohotkey">loop 12
{
n := 1983+A_Index
Line 737 ⟶ 781:
 
2017 丁酉 dīng-yŏu Fire 火 huǒ Rooster 鸡 jī yīn 阴 34/60</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f CHINESE_ZODIAC.AWK
BEGIN {
Line 768 ⟶ 811:
2017 Fire Rooster Yin
</pre>
=={{header|BASIC}}==
 
==={{header|BASIC256}}===
<syntaxhighlight lang=BASIC256"basic256">
# Chinese zodiac
 
Line 806 ⟶ 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}}==
 
<syntaxhighlight lang="befunge">0" :raeY">:#,_55+"< /8"&>+:66+%00p:55+v
v"Aspect: "0++88*5%2\0\+1%"<":p01++66/2%<
>00g5g7-0" :laminA"10g5g"<"+0" :tnemelE"v
Line 825 ⟶ 996:
Aspect: yang
Cycle: 35 / 60</pre>
 
=={{header|C}}==
{{trans|C++}}
<syntaxhighlight lang="c">#include <math.h>
#include <stdio.h>
 
Line 870 ⟶ 1,040:
1976 is the year of the Fire Dragon (yang).
2017 is the year of the Fire Rooster (yin).</pre>
 
=={{header|C sharp|C#}}==
{{trans|Java}}
<syntaxhighlight lang="csharp">using System;
 
namespace ChineseZodiac {
Line 909 ⟶ 1,078:
1985 is the year of the Wood Ox (yin). 乙丑
2017 is the year of the Fire Rooster (yin). 丁酉</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <iostream>
#include <cmath>
 
Line 961 ⟶ 1,129:
2017 is the year of the Fire Rooster (yin).
</pre>
 
=={{header|Clojure}}==
<syntaxhighlight lang="clojure">(def base-year 4)
(def celestial-stems ["甲" "乙" "丙" "丁" "戊" "己" "庚" "辛" "壬" "癸"])
(def terrestrial-branches ["子" "丑" "寅" "卯" "辰" "巳" "午" "未" "申" "酉" "戌" "亥"])
Line 1,005 ⟶ 1,172:
2017: 丁酉 (dīng-yŏu, Fire Rooster; yin - cycle 34/60)
</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
1020 poke 53280,2: rem red border
Line 1,084 ⟶ 1,250:
=={{header|Common Lisp}}==
{{trans|Ruby}}
<syntaxhighlight lang="lisp">; Any CE Year that was the first of a 60-year cycle
(defconstant base-year 1984)
 
Line 1,153 ⟶ 1,319:
1976: 丙辰 (bĭng-chén, Fire Dragon; yang)
</pre>
 
=={{header|D}}==
{{trans|haskell}}
<syntaxhighlight lang=D"d">import std.stdio;
 
// 10 heavenly stems
Line 1,243 ⟶ 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,248 ⟶ 1,442:
{{libheader| System.Math}}
{{Trans|C#}}
<syntaxhighlight lang=Delphi"delphi">
program Chinese_zodiac;
 
Line 1,347 ⟶ 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}}==
Line 1,356 ⟶ 1,584:
 
{{Works with|Office 365 betas 2021}}
<syntaxhighlight lang="lisp">CNZODIAC
=LAMBDA(y,
APPENDCOLS(
Line 1,499 ⟶ 1,727:
and also assuming the following generic bindings in the Name Manager for the WorkBook:
 
<syntaxhighlight lang="lisp">APPENDCOLS
=LAMBDA(xs,
LAMBDA(ys,
Line 1,754 ⟶ 1,982:
 
=={{header|F Sharp|F#}}==
<syntaxhighlight lang="fsharp">
open System
 
Line 1,788 ⟶ 2,016:
2017 is the year of the Fire Rooster (Yin)
</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: circular formatting io kernel math qw sequences
sequences.repeating ;
IN: rosetta-code.zodiac
Line 1,831 ⟶ 2,058:
1985 is the year of the Wood Ox (yin).
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"}
dim as string elements(0 to 4) = {"Wood", "Fire", "Earth", "Metal", "Water"}
dim as string animals(0 to 11) = {"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",_
Line 1,860 ⟶ 2,121:
2186 is the year of the Earth Dog (yang).
76543 is the year of the Water Rabbit (yin).</pre>
 
=={{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]]
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.
 
[[File:Fōrmulæ - Chinese zodiac 03.png]]
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
 
import "fmt"
Line 1,909 ⟶ 2,175:
1976: Fire Dragon, Yang, Cycle year 53 丙辰
</pre>
 
=={{header|Groovy}}==
{{trans|Java}}
<syntaxhighlight lang="groovy">class Zodiac {
final static String[] animals = ["Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"]
final static String[] elements = ["Wood", "Fire", "Earth", "Metal", "Water"]
Line 1,942 ⟶ 2,207:
1985 is the year of the Wood Ox (yin). 乙丑
2017 is the year of the Fire Rooster (yin). 丁酉</pre>
 
=={{header|Haskell}}==
(We can use Chinese characters in Haskell names, as long as the first character is lower-case alphabetic)
<syntaxhighlight lang="haskell">import Data.Array (Array, listArray, (!))
 
------------------- TRADITIONAL STRINGS ------------------
Line 2,077 ⟶ 2,341:
dīngyŏu huǒ jī yīn
34/60 fire rooster </pre>
 
=={{header|J}}==
<syntaxhighlight lang=J"j"> ELEMENTS=: _4 |. 2 # ;:'Wood Fire Earth Metal Water'
YEARS=: 1935 1938 1968 1972 1976 2017
 
Line 2,121 ⟶ 2,384:
2017 丁 酉 ( yin )
</syntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang=Java"java">public class Zodiac {
 
final static String animals[]={"Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig"};
Line 2,163 ⟶ 2,425:
2017 is the year of the Fire Rooster (yin). 丁酉
</pre>
 
=={{header|JavaScript}}==
 
===ES6===
{{Trans|Haskell}}
<syntaxhighlight lang=JavaScript"javascript">(() => {
"use strict";
 
Line 2,383 ⟶ 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}}==
Line 2,388 ⟶ 2,710:
{{trans|Python}}
 
<syntaxhighlight lang="julia">function chinese(year::Int)
pinyin = Dict(
"甲" => "jiă",
Line 2,456 ⟶ 2,778:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.1.2
 
class ChineseZodiac(val year: Int) {
Line 2,517 ⟶ 2,839:
2017 丁酉 dīng-yŏu Fire Rooster Yin 34/60
</pre>
 
=={{header|Lua}}==
{{trans|C}}
<syntaxhighlight lang="lua">local ANIMALS = {"Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig"}
local ELEMENTS = {"Wood","Fire","Earth","Metal","Water"}
 
Line 2,561 ⟶ 2,882:
1976 is the year of the Fire Dragon (yang)
2017 is the year of the Fire Rooster (yin)</pre>
 
=={{header|Maple}}==
<syntaxhighlight lang=Maple"maple">
zodiac:=proc(year::integer)
local year60,yinyang,animal,element;
Line 2,573 ⟶ 2,893:
end proc:
</syntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica"mathematica">pinyin = <|"甲" -> "jiă", "乙" -> "yĭ", "丙" -> "bĭng", "丁" -> "dīng",
"戊" -> "wù", "己" -> "jĭ", "庚" -> "gēng", "辛" -> "xīn",
"壬" -> "rén", "癸" -> "gŭi", "子" -> "zĭ", "丑" -> "chŏu",
Line 2,622 ⟶ 2,941:
1972: 壬子 (rén-zĭ, Water Rat; yang)
1976: 丙辰 (bĭng-chén, Fire Dragon; yang)</pre>
 
=={{header|Modula-2}}==
{{trans|C++}}
<syntaxhighlight lang="modula2">MODULE ChineseZodiac;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,ReadChar;
Line 2,678 ⟶ 2,996:
ReadChar
END ChineseZodiac.</syntaxhighlight>
 
=={{header|Nim}}==
{{trans|Rust}}
<syntaxhighlight lang="nim">import strformat
 
const ANIMALS: array[12, string] = ["Rat", "Ox",
Line 2,740 ⟶ 3,057:
2020 庚子 gēng-zĭ Metal Rat Yang 37/60
</pre>
 
=={{header|Pascal}}==
{{works with|Extended Pascal}}
The built-in functions <tt>pred</tt> and <tt>succ</tt> accepting a second (optional) parameter is an Extended Pascal (ISO 10206) extension, as well as the possibility of specifying <tt>record</tt> literals.
<syntaxhighlight lang="pascal">type
animalCycle = (rat, ox, tiger, rabbit, dragon, snake,
horse, goat, monkey, rooster, dog, pig);
Line 2,765 ⟶ 3,081:
]
end;</syntaxhighlight>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">sub zodiac {
my $year = shift;
my @animals = qw/Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey Rooster Dog Pig/;
Line 2,797 ⟶ 3,112:
2017: 丁酉 (dīng-yŏu) Fire Rooster; yin - year 34 of the cycle
</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">animals</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Rat"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Ox"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Tiger"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Rabbit"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Dragon"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Snake"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Horse"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Goat"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Monkey"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Rooster"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Dog"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Pig"</span><span style="color: #0000FF;">},</span>
Line 2,825 ⟶ 3,139:
2018: Earth Dog; yang, year 35 of the cycle.
</pre>
 
=={{header|Picat}}==
{{trans|Prolog}}
{{works with|Picat}}
<syntaxhighlight lang=Picat"picat">
animals({"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"}).
 
Line 2,887 ⟶ 3,200:
2017 is the year of the Fire Rooster (yin). 丁酉
</pre>
 
=={{header|PowerShell}}==
{{trans|Ruby}}
<syntaxhighlight lang=PowerShell"powershell">
function Get-ChineseZodiac
{
Line 2,977 ⟶ 3,289:
}
</syntaxhighlight>
<syntaxhighlight lang=PowerShell"powershell">
1935, 1938, 1968, 1972, 1976 | Get-ChineseZodiac | Format-Table
</syntaxhighlight>
Line 2,991 ⟶ 3,303:
</pre>
Defaults to the current year:
<syntaxhighlight lang=PowerShell"powershell">
Get-ChineseZodiac
</syntaxhighlight>
Line 3,005 ⟶ 3,317:
</pre>
Using the '''Year''' property of a <code>[DateTime]</code> object:
<syntaxhighlight lang=PowerShell"powershell">
Get-Date "11/8/2016" | Get-ChineseZodiac
</syntaxhighlight>
Line 3,019 ⟶ 3,331:
</pre>
Emulate the Ruby script's output:
<syntaxhighlight lang=PowerShell"powershell">
$zodiacs = 1935, 1938, 1968, 1972, 1976 | Get-ChineseZodiac
 
Line 3,041 ⟶ 3,353:
1976: 丙辰 (bĭng-chén, Fire Dragon; yang - year 53 of the cycle)
</pre>
 
=={{header|Prolog}}==
{{trans|Java}}
{{works with|GNU Prolog}}
<syntaxhighlight lang=Prolog"prolog">
:- initialization(main).
 
Line 3,116 ⟶ 3,427:
2017 is the year of the Fire Rooster (yin). 丁酉
</pre>
 
=={{header|PureBasic}}==
<syntaxhighlight lang=pureBasic"purebasic">EnableExplicit
#BASE=4
#SPC=Chr(32)
Line 3,179 ⟶ 3,489:
1984 Wood Rat yang 1 jiă-zĭ 甲子
2017 Fire Rooster yin 34 dīng-yŏu 丁酉</pre>
 
=={{header|Python}}==
{{trans|Ruby}}
<syntaxhighlight lang=Python"python">
# coding: utf-8
 
Line 3,252 ⟶ 3,561:
Or, segmenting tokens just in time, and writing out wiki tables:
{{Works with|Python|3.7}}
<syntaxhighlight lang="python">'''Chinese zodiac'''
 
from functools import (reduce)
Line 3,556 ⟶ 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}}
 
<syntaxhighlight lang="racket">#lang racket
 
(require racket/date)
Line 3,615 ⟶ 3,960:
1972: 壬子 (rén-zĭ, Water Rat; yang)
1976: 丙辰 (bĭng-chén, Fire Dragon; yang)</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
Line 3,621 ⟶ 3,965:
{{trans|Ruby}}
 
<syntaxhighlight lang="raku" line>sub Chinese-zodiac ( Int $year ) {
my @heaven = <甲 jiă 乙 yĭ 丙 bĭng 丁 dīng 戊 wù 己 jĭ 庚 gēng 辛 xīn 壬 rén 癸 gŭi>.pairup;
my @earth = <子 zĭ 丑 chŏu 寅 yín 卯 măo 辰 chén 巳 sì 午 wŭ 未 wèi 申 shēn 酉 yŏu 戌 xū 亥 hài>.pairup;
Line 3,658 ⟶ 4,002:
1984: 甲子 (jiăzĭ, Wood Rat; yang - year 1 in the cycle)
2017: 丁酉 (dīngyŏu, Fire Rooster; yin - year 34 in the cycle)</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
yinyang = ["yang", "yin"]
elements = ["Wood", "Fire", "Earth", "Metal", "Water"]
Line 3,685 ⟶ 4,028:
2186 is the year of the Earth Dog (yang).
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>
 
Line 3,690 ⟶ 4,048:
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.
 
<syntaxhighlight lang="ruby"># encoding: utf-8
pinyin = {
'甲' => 'jiă',
Line 3,770 ⟶ 4,128:
=={{header|Rust}}==
{{trans|Kotlin}}
<syntaxhighlight lang=Rust"rust">fn chinese_zodiac(year: usize) -> String {
static ANIMALS: [&str; 12] = [
"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
Line 3,835 ⟶ 4,193:
1984 甲子 jiă-zĭ Wood Rat Yang 01/60
2017 丁酉 dīng-yŏu Fire Rooster Yin 34/60</pre>
 
=={{header|Scala}}==
<syntaxhighlight lang=Scala"scala">object Zodiac extends App {
val years = Seq(1935, 1938, 1968, 1972, 1976, 1984, 1985, 2017, 2018)
 
Line 3,874 ⟶ 4,231:
}</syntaxhighlight>
{{Out}}See it in running in your browser by [https://scalafiddle.io/sf/O6MUr27/0 ScalaFiddle (JavaScript)] or by [https://scastie.scala-lang.org/KXC0j71ORFaQxNZSCCZ1Aw Scastie (JVM)].
 
=={{header|Seed7}}==
The standard output file of Seed7 accepts only Latin-1 (byte) output.
Line 3,881 ⟶ 4,237:
The library [http://seed7.sourceforge.net/libraries/console.htm console.s7i] defines STD_CONSOLE.
 
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "console.s7i";
 
Line 3,915 ⟶ 4,271:
2017 is the year of the Fire Rooster (yin). 丁酉
</pre>
 
=={{header|Sidef}}==
{{trans|Perl}}
<syntaxhighlight lang="ruby">func zodiac(year) {
var animals = %w(Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey Rooster Dog Pig)
var elements = %w(Wood Fire Earth Metal Water)
Line 3,948 ⟶ 4,303:
2017: 丁酉 (dīng-yŏu) Fire Rooster; yin - year 34 of the cycle
</pre>
 
=={{header|tbas}}==
<syntaxhighlight lang="qbasic">
DATA "甲","乙","丙","丁","戊","己","庚","辛","壬","癸"
DECLARE celestial$(10)
Line 4,035 ⟶ 4,389:
 
</pre>
 
=={{header|Tcl}}==
<syntaxhighlight lang=Tcl"tcl">
proc cn_zodiac year {
set year0 [expr $year-4]
Line 4,061 ⟶ 4,414:
丁酉 ding1-you3 Fire Rooster (yin) year 34
</pre>
 
=={{header|uBasic/4tH}}==
{{works with|R3}}
<syntaxhighlight lang="text">dim @y(2) ' yin or yang
dim @e(5) ' the elements
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,269 ⟶ 4,620:
1972:壬子(rén-zĭ, Water Rat; yang)
1976:丙辰(bĭng-chén, Fire Dragon; yang)</pre>
 
=={{header|UTFool}}==
 
<syntaxhighlight lang=UTFool"utfool">
···
http://rosettacode.org/wiki/Chinese_zodiac
Line 4,313 ⟶ 4,663:
wuxing[2][stem / 2], shengxiao[2][branch]
</syntaxhighlight>
 
=={{header|VBScript}}==
To run in console mode with cscript.
<syntaxhighlight lang="vb">' Chinese zodiac - VBS
 
Animals = array( "Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig" )
Line 4,342 ⟶ 4,691:
2017 is the year of the Fire Rooster (Yin).
</pre>
 
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<syntaxhighlight lang="vbnet">Module Module1
 
ReadOnly ANIMALS As String() = {"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"}
Line 4,385 ⟶ 4,733:
1985 is the year of the Wood Ox (yin). 乙丑
2017 is the year of the Fire Rooster (yin). 丁酉</pre>
=={{header|V (Vlang)}}==
 
=={{header|Vlang}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">const (
animal_string = ["Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
"Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"]
Line 4,423 ⟶ 4,770:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang=ecmascript"wren">import "./fmt" for Fmt
 
class ChineseZodiac {
Line 4,482 ⟶ 4,829:
</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"yabasic">
dim Animals$(12) : for a = 0 to 11 : read Animals$(a) : next a
dim Elements$(5) : for a = 0 to 4 : read Elements$(a): next a
Line 4,516 ⟶ 4,902:
2017 is the year of the Fire Rooster (Yin).
</pre>
 
 
=={{header|zkl}}==
{{trans|Ruby}}
<syntaxhighlight lang="zkl">fcn ceToChineseZodiac(ce_year){ // --> list of strings
# encoding: utf-8
var [const] pinyin=SD( // create some static variables, SD is small fixed dictionary
Line 4,552 ⟶ 4,936:
stem_pinyin,branch_pinyin, element,animal,aspect)
}</syntaxhighlight>
<syntaxhighlight lang="zkl">foreach ce_year in (T(1935,1938,1968,1972,1976,Time.Clock.UTC[0])){
println("%d: %s%s (%s-%s, %s %s; %s)"
.fmt(ce_year,ceToChineseZodiac(ce_year).xplode()));
1,479

edits