You are given a year $year.
Write a script to determine the Chinese Zodiac for the given year $year. Please check out wikipage for more information about it.
#!/usr/bin/env tclsh
# You are given a year $year.
# Write a script to determine the Chinese Zodiac
# for the given year $year.
if {$argc >= 1} {
set year [lindex $argv 0]
} elseif {$argc == 0} {
puts "Please input a year."
exit
}
if {$year <= 0} {
puts "Year requires > 0."
exit
}
# The animal cycle: Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat,
# Monkey, Rooster, Dog, Pig.
# The element cycle: Wood, Fire, Earth, Metal, Water.
set animal [list Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat]
set element [list Metal Metal Water Water Wood Wood Fire Fire Earth Earth]
set a [lindex $animal [expr $year % 12]]
set e [lindex $element [expr $year % 10]]
puts "$e $a"
沒有留言:
張貼留言