Chinese zodiac: Difference between revisions

Add Factor example
(Added Rust)
(Add Factor example)
Line 722:
1985 is the year of the Wood Ox (Yin)
2017 is the year of the Fire Rooster (Yin)
</pre>
 
=={{header|Factor}}==
<lang factor>USING: circular formatting io kernel math qw sequences
sequences.repeating ;
IN: rosetta-code.zodiac
 
<PRIVATE
 
! Offset start index by -4 because first cycle started on 4 CE.
: circularize ( seq -- obj )
[ -4 ] dip <circular> [ change-circular-start ] keep ;
 
: animals ( -- obj )
qw{
Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey
Rooster Dog Pig
} circularize ;
 
: elements ( -- obj )
qw{ Wood Fire Earth Metal Water } 2 <repeats> circularize ;
 
PRIVATE>
 
: zodiac ( n -- str )
dup [ elements nth ] [ animals nth ]
[ even? "yang" "yin" ? ] tri
"%d is the year of the %s %s (%s)." sprintf ;
 
: zodiac-demo ( -- )
{ 1935 1938 1968 1972 1976 1984 1985 2017 }
[ zodiac print ] each ;
 
MAIN: zodiac-demo</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>
 
1,827

edits