Okay, so I wanted to do something fun with coding and came across this idea about the Chinese zodiac. I found some old stuff online saying 1851 was the year of the Pig, so I thought, “Let’s see if I can make something that figures out the zodiac animal for any year, starting with 1851 as a base.”
First, I grabbed my laptop and opened up my usual coding program. I like to keep things simple, you know? No fancy setups here. Just me and the code.

Getting Started
I started by thinking about how the zodiac works. It’s a 12-year cycle, right? So, I needed a way to take any year, figure out how many years it is from 1851, and then use the remainder after dividing by 12 to find the animal.
The Process
- I created a simple list, or should I say, an array with these animals in order.
- Then, I wrote a little function. Basically, I took the input year and subtracted 1851 from it. This gives us the difference in years.
- After that, I used the modulo operator (%) with 12. That is maybe a bit of complex word, it just means I found the remainder after dividing by 12. Like, if the difference is 14, then 14 % 12 is 2. This remainder is super useful!
Putting It All Together
Finally, I used that remainder as the index to look up the animal in my array. Because I had the Pig at index 0, a remainder of 0 means Pig, 1 means Dog, and so on. It’s all about lining things up correctly.
The Final Code
I am not going to show the code,because it is ugly,I just want to share this interesting thing.
It was really interesting!
I tested it with a few different years, and it worked. I was pretty stoked. It’s not every day you get to combine ancient traditions with some basic coding. This little project showed me, once again, that even simple ideas can be pretty cool when you bring them to life.
