After learning about modulo function, I finally have an elegant algorithm to find out the Chinese horoscope sign based on the year of input. It came from an innocent enough question from facebook - what's the value of m+n, such that 2012^m and 2012^n has the same last 3 digits, if m and n are integers are m is greater than m?
I did a bit of exploring and found out the answer by doing it through excel. Then I discovered the modulo function, and then I also discovered the theorem that if a = b (mod m), then a^c = b^c (mod m). It's vastly different from learning about mathematical theorem through books or teachers, and learning about it through discovery. The joy of solving the puzzle is immensely satisfying.
But first of all, what's the modulo function?
Modulo function has two inputs i.e. MOD (a, b). Basically the function just returns you the number that is the remainder if a is divided by b. For example, MOD (12, 3) = 0 because 12 divided by 3 gives no remainder. MOD (12, 5) = 2 because 12 divided by 5 gives a remainder of 2.
My algorithm to find out the Chinese astrological sign is to take the input year, subtract 4 to it, modulo it to 12, then add 1 to the result. You can use it on excel.
i.e. Let x be the input year
y = MOD(x-4, 12) + 1
The output y will give you a number ranging from 1 to 12, so
1 is rat,
2 is ox,
3 is tiger,
4 is rabbit,
5 is dragon,
6 is snake,
7 is horse,
8 is goat,
9 is monkey,
10 is rooster,
11 is dog and
12 is pig.
To illustrate this, let's try out the year 3194:
So in the year 3194, y = MOD(3194-4, 12) +1 = 11, so it’s the year of the dog.
I did a bit of exploring and found out the answer by doing it through excel. Then I discovered the modulo function, and then I also discovered the theorem that if a = b (mod m), then a^c = b^c (mod m). It's vastly different from learning about mathematical theorem through books or teachers, and learning about it through discovery. The joy of solving the puzzle is immensely satisfying.
But first of all, what's the modulo function?
Modulo function has two inputs i.e. MOD (a, b). Basically the function just returns you the number that is the remainder if a is divided by b. For example, MOD (12, 3) = 0 because 12 divided by 3 gives no remainder. MOD (12, 5) = 2 because 12 divided by 5 gives a remainder of 2.
My algorithm to find out the Chinese astrological sign is to take the input year, subtract 4 to it, modulo it to 12, then add 1 to the result. You can use it on excel.
i.e. Let x be the input year
y = MOD(x-4, 12) + 1
The output y will give you a number ranging from 1 to 12, so
1 is rat,
2 is ox,
3 is tiger,
4 is rabbit,
5 is dragon,
6 is snake,
7 is horse,
8 is goat,
9 is monkey,
10 is rooster,
11 is dog and
12 is pig.
To illustrate this, let's try out the year 3194:
So in the year 3194, y = MOD(3194-4, 12) +1 = 11, so it’s the year of the dog.







