Monday, February 29, 2016

Experience Quadrennial Magic!

Today is the leap day in 2016!

Every four years, we add an extra day to February to account for the extra four quarters of days we accumulate over the past four years. While there are many videos and articles online explaining the significance, maths, and history behind the leap day, I'm here to give you what I do best: some algorithms!

Below is some menial code that could be used to determine if a particular calendar year is actually a leap year. The rules for being a leap year are as follows:


  • if the year is divisible by 4, then it cannot be a leap year, otherwise:
  • if the year is not divisible by 100, then it is a LEAP YEAR, otherwise:
  • if the year is not divisible by 400, then it cannot be a leap year, otherwise:
  • the year is a leap year.
*By our formula, illustrated below, 2000 is a common year, though it was actually a leap year!*


But if you're a fan of O'Nealio, you know that this is too easy. We need to dig deeper, much deeper. Let's take a look at the relative error of this method of calculating leap years. To understand this, it's important to note the measurement of how many Earth days it takes for a complete orbit around the Sun, called a tropical year: 365.2421891 days. So by the current Gregorian Calendar that we use, a year contains 365.2425 days. This means that the error (drift) produced by being just off the actual orbit of the Earth would be an extra day about every 3,216 years. That's pretty good, and given that we've really only scraped the surface of the calendar since it was put into usage in the late 1800's, we've got a lot of time before we have to worry about extra days.

But how far can we take this? Is 3,216 years enough time for man and their understanding of civics to catch up and add an extra day? I think we can do better than that!

Resources: