Scripting for Fun (2)

2 Name: Nameless : 2026/01/22 03:48

Using Elisp, determine the Chinese Zodiac sign for a given year.

(defvar cz-animals
'(rat
ox
tiger
rabbit
dragon
snake
horse
goat
monkey
rooster
dog
pig)
"These are the 12 animals of the Chinese Zodiac.")

(defun cz-animal (year)
"Return Chinese Zodiac animal for YEAR."
(let* ((offset (mod (- year 4) 12)))
(nth offset cz-animals)))

(defvar cz-elements
'(wood
fire
earth
metal
water)
"These are the 5 elements of the Chinese Zodiac.")

(defun cz-element (year)
"Return Chinese Zodiac element for YEAR."
(let* ((offset (/ (mod (- year 4) 10) 2)))
(nth offset cz-elements)))

(defun cz-sign (year)
"Return the Chinse Zodiac element and animal sign for the given YEAR."
(list (cz-element year) (cz-animal year)))
Name: E-Mail:
Leave these fields empty (spam trap):