Chinese zodiac: Difference between revisions

Content added Content deleted
(Chinese zodiac en Yabasic)
No edit summary
Line 2,366: Line 2,366:
end proc:
end proc:
</lang>
</lang>

=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>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"|>;
animals = {"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse",
"Goat", "Monkey", "Rooster", "Dog", "Pig"};
elements = {"Wood", "Fire", "Earth", "Metal", "Water"};
celestial = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
terrestrial = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌",
"亥"};
aspects = {"yang", "yin"};
ClearAll[calculate]
calculate[year_] := Module[{BASE, cycleyear, stemnumber, stempinyin, element,
elementnumber, branchnumber, branchhan, branchpinyin, animal,
aspectnumber, aspect, stemhan},
BASE = 4;
cycleyear = year - BASE;
stemnumber = Mod[cycleyear + 1, 10, 1];
stemhan = celestial[[stemnumber]];
stempinyin = pinyin[[stemhan]];
elementnumber = Floor[stemnumber/2 + 1/2];
element = elements[[elementnumber]];
branchnumber = Mod[cycleyear + 1, 12, 1];
branchhan = terrestrial[[branchnumber]];
branchpinyin = pinyin[[branchhan]];
animal = animals[[branchnumber]];
aspectnumber = Mod[cycleyear + 1, 2, 1];
aspect = aspects[[aspectnumber]];
Row@{year, ": ", stemhan, branchhan, " (", stempinyin, "-", branchpinyin, ", ", element, " ", animal, "; ", aspect, ")"}
]
calculate[1935]
calculate[1938]
calculate[1941]
calculate[1947]
calculate[1968]
calculate[1972]
calculate[1976]</lang>
{{out}}
<pre>1935: 乙亥 (yĭ-hài, Wood Pig; yin)
1938: 戊寅 (wù-yín, Earth Tiger; yang)
1941: 辛巳 (xīn-sì, Metal Snake; yin)
1947: 丁亥 (dīng-hài, Fire Pig; yin)
1968: 戊申 (wù-shēn, Earth Monkey; yang)
1972: 壬子 (rén-zĭ, Water Rat; yang)
1976: 丙辰 (bĭng-chén, Fire Dragon; yang)</pre>


=={{header|Modula-2}}==
=={{header|Modula-2}}==