Today, I wanted to play around with something different – the Chinese zodiac. I’ve always been curious about it, and I figured, why not try to make something that shows the zodiac animal for any given year? So, I set out to do just that, focusing on the years 1820 and onwards. This will not cover date before 1820.
I started by doing some digging. I needed to know the order of the animals and how they cycle. It’s a 12-year cycle, so that part was pretty straightforward. I made a list to keep things organized:
- Rat
- Ox
- Tiger
- Rabbit
- Dragon
- Snake
- Horse
- Goat
- Monkey
- Rooster
- Dog
- Pig
Next, I needed a starting point. Which animal corresponded to the year 1820? After a bit of searching, I found out that 1820 was a Dragon year. Perfect! That gave me the anchor I needed.
The real challenge was figuring out the formula. Since it’s a 12-year cycle, I knew I’d need to use the modulo operator (%). I messed around with it for a while, subtracting 1820 from the input year and then taking the modulo by 12. That seemed to do the trick! It gave me a number between 0 and 11, which I could then use to look up the correct animal in my list.
To actually implement this,I used python to build this, although other tools can be used I think python is the simplest. Put it all together,I added my own makeshift print sentence, and it finally works!
It was a fun little project! It’s always satisfying to take something you’re curious about and turn it into a working thing. And now I have a handy way to figure out Chinese zodiac animals for any year (from 1820 onwards, at least).