← Back to challenges

Sexagenary Cycle (Chinese Zodiac)

PythonHardlanguage_fundamentalsloops

Instructions

In early recorded Chinese history, time was reckoned using the sexagenary (60-year) cycle, generated from two subcycles:

  1. Five heavenly stems (elements) in this order: wood, fire, earth, metal, water. The stems change every two years.
  2. Twelve earthly branches (animals) in this order: rat, ox, tiger, rabbit, dragon, snake, horse, sheep, monkey, rooster, dog, pig. The branches change yearly.

The combinations between these two sub-cycles result in a 60-year cycle where no two years are the same — for example, the 5 years of the Rat have 5 different elements: 1924 Wood Rat, 1936 Fire Rat, 1948 Earth Rat, 1960 Metal Rat, 1972 Water Rat.

The first 14 years of the current cycle are shown in the table below:

Gregorian YearStemBranch
1984WoodRat
1985WoodOx
1986FireTiger
1987FireRabbit
1988EarthDragon
1989EarthSnake
1990MetalHorse
1991MetalSheep
1992WaterMonkey
1993WaterRooster
1994WoodDog
1995WoodPig
1996FireRat
1997FireOx

These days, the sexagenary cycle is used mainly for historical celebrations and events, and in Chinese astrology. The Gregorian calendar is now the standard means of reckoning time.

Create a function that takes a number representing a year in the Gregorian calendar, and returns a string consisting of the corresponding stem-and-branch combination in the sexagenary cycle.

Examples

sexagenary(1971) ➞ "Metal Pig"

sexagenary(1927) ➞ "Fire Rabbit"

sexagenary(1974) ➞ "Wood Tiger"

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.