Jump to content

Chinese zodiac: Difference between revisions

(→‎{{header|Picat}}: Adding Picat)
Line 2,748:
1976: Fire Dragon; yang, year 53 of the cycle.
2018: Earth Dog; yang, year 35 of the cycle.
</pre>
 
=={{header|Picat}}==
{{trans|Prolog}}
{{works with|Picat}}
<lang Picat>
animals({"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"}).
 
elements({"Wood", "Fire", "Earth", "Metal", "Water"}).
 
animal_chars({"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"}).
 
element_chars({{"甲", "丙", "戊", "庚", "壬"}, {"乙", "丁", "己", "辛", "癸"}}).
 
years({1935, 1938, 1968, 1972, 1976, 1984, 1985, 2017}).
 
year_animal(Year) = Animal =>
I = ((Year - 4) mod 12) + 1,
animals(Animals),
Animal = Animals[I].
 
year_element(Year) = Element =>
I = ((Year - 4) mod 10) div 2 + 1,
elements(Elements),
Element = Elements[I].
 
year_animal_char(Year) = AnimalChar =>
I = (Year - 4) mod 12 + 1,
animal_chars(AnimalChars),
AnimalChar = AnimalChars[I].
 
year_element_char(Year) = ElementChar =>
I1 = Year mod 2 + 1,
element_chars(ElementChars),
ElementChars1 = ElementChars[I1],
I2 = (Year - 4) mod 10 div 2 + 1,
ElementChar = ElementChars1[I2].
 
year_yin_yang(Year) = YinYang =>
Year mod 2 == 0 -> YinYang = "yang" ; YinYang = "yin".
 
main :-
years(Years),
foreach (Year in Years)
Element = year_element(Year),
Animal = year_animal(Year),
YinYang = year_yin_yang(Year),
ElementChar = year_element_char(Year),
AnimalChar = year_animal_char(Year),
printf("%d is the year of the %w %w (%w). %w%w\n", Year, Element, Animal, YinYang, ElementChar, AnimalChar)
end.
</lang>
{{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>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.