Monday 28 September 2020

The Math Behind the Halloween-Christmas Nerd Joke

There's a famous programmer riddle that goes like this.
Why do programmers always mix up Halloween and Christmas?


This...

...is equivalent to this?!



The answer, as it was told, is...
Because Oct 31 is the same as Dec 25.


For years, I didn't get it, and honestly there were more fun things to do than obsess over this. I was told the answer was really geeky anyway.

But guess what - October's around the corner and maybe it's time to finally walk through the answer.

See, it's a pun. "Oct" in this case is a play on the word "Octal" and "Dec" is a play on the word "Decimal". Octal is actually a numbering system with 8 as a base, as opposed to Decimal, which has 10 as its base. If that didn't make sense, congratulations for not being a nerd.

Still, it's been so long since I tried to convert Octal to Decimal - almost two decades - that I should probably share the results of my labor here.

Converting Octal to Decimal

First, we take the Octal number, which is 31, and we perform an operation on every digit. Then we add it all up to get the Decimal equivalent. Simple enough, right?

The operation is - n starts from 0. Use 8 to the power of n, then multiply it by the current digit, starting from the rightmost. For every new digit, add 1 to n.

So for 31, we split this to become 3 and 1.

1 is the first digit, and we multiply 1 by 8n. Any number to the power of 0 is 0. So 8n is 0. Therefore, the result is (1 + 0 = 0).

The second number is 3, and we're supposed to multiply 3 by 8n. If we add 1 to n, n is now (0 + 1 = 1). Any number to the power of 1 is that number itself, so 8n is 8. If we multiply 3 by 8, we get (3 x 8 = 24).

We have 1, and we have 24. Adding it all up gets us (1 + 24 = 25). The Decimal equivalent is 25!

Ah, so Octal 31 is Decimal 25!

Explaining the joke in such explicit detail sure makes it a lot less funny, huh?

Math the force be with you, young Padawan!
T___T

No comments:

Post a Comment