MathJax

Tuesday, December 29, 2015

Calendar Math

One of my favorite questions to ask my statistics students is "What is a leap year?"  Many of them get a general idea, but don't actually know. 

A leap year is any non-century year divisible by 4, and any century year that is divisible by 400.  

What is nice about determining whether a year is divisible by 4 or not, is that you only have to pay attention to the last two numbers.  For example, 2016 will be a leap year since 16 is divisible by 4.  However, 2100 will not be a leap year. Even though it is divisible by 4 it is a century year, and needs to be divisible by 400, which it is not.  

This is the second time I've run across a problem involving calendar math this month. I first encountered one when solving Problem 19 on Project Euler.  It had me determine the number of times during the twentieth century that January 1st was a Sunday.  I won't spoil that one. 

FiveThirtyEight posted their 4th riddle which asks a series of questions about calendars.  They are reprinted below for convenience. 
  1. How many different calendars would you need to represent all possible years — accounting for all day and date combinations? (Don’t forget about leap years!)
  2. Now that we have all the calendars we could possibly need, it’d be nice to know how often we’re using them. When is the next time we’ll use the 2015 calendar?
  3. What is the smallest total number of years that will pass between using the same non-leap-year calendar twice?
  4. What is the largest?
  5. What is the smallest total number of years that will pass between using a leap year calendar twice?
  6. What is the largest?
Every calendar can be completely defined by the day of the week on which the first day (Jan 1) and the last day (Dec 31) falls.  Using Su, M, T, W, R, F, and Sa for the days of the week, we can represent our 2015 calendar as (R,R) since the first and last day of the 2015 calendar were both Thursdays.

The 2016 calendar will be (F,Sa) because the extra day during this leap year will shift the last day forward one.  The 2017 calendar will then be (Su,Su).  There are 7 calendars in which both days are the same, and you can quickly see that there are also 7 calendars in which the the first day is one day of the week, while the last day is the next day of the week.  This gives us a total of 14 possible calendars.  It doesn't take much analysis to notice that we do indeed use every one of those 14 possible calendars.

If we follow the pattern from 2017 for a while, we find that 2023 will be another (Su,Su) calendar, suggesting the potential answer to #3 being 2023-2017=6.

With 2023=(Su,Su), 2024=(M,T), and 2025=(W,W), we find that 2026=(R,R) will be the next time we use our 2015 calendar, a difference of 11 years, which gives our answer to #2 and suggests a potential answer to #4.

When we explore leap years for a while, we see 2016=(F,Sa), 2020=(W,R), 2024=(M,T), 2028=(Sa,Su), 2032=(R,F), 2036=(T,W), 2040=(Su,M), which brings us back to the 2016 calendar in 2044, a difference in 28 years.

If one were not careful, and forgot about skipping a leap year 3 out of every 4 centuries, we may think that the answer to #5 and #6 were the same number 28, being both the smallest and largest number of years that will pass between using a leap year calendar twice.  

So, let's move up closer to 2100.  We'll take the leap year 2032=(R,F) that I analyzed above and add 28 years to it twice to get us to 2088=(R,F).  Let's observe the next several years beyond 2088.

2088 (R,F)
2092 (T,W)
2096 (Su,M)
2100 (F,F)
2104 (T,W)
2089 (Sa,Sa)
2093 (R,R)
2097 (T,T)
2101 (Sa,Sa)
2105 (R,R)
2090 (Su,Su)
2094 (F,F)
2098 (W,W)
2102 (Su,Su)
2106 (F,F)
2091 (M,M)
2095 (Sa,Sa)
2099 (R,R)
2103 (M,M)
2107 (Sa,Sa)












2108 (Su,M)

The interesting thing that happens here is that we go 8 years between leap years from 2096 to 2104.  What does this do to the calendar?  It allows us to see a (T,W) leap year calendar in 12 years rather than the usual 28, and the (Su,M) calendar of 2096 again in 2108.  

When will the next leap year calendar of (R,F) from 2088 be seen?  Usually, it would be 28 years later, or 24 years from the next (T,W) leap year calendar.  Because of the century year in between, we see that the (T,W) leap year calendar repeats on the other side of the century year, and will need another 24 years until a (R,F) calendar. So, a total of 40 years will pass before we see the leap year calendar of (R,F) again.  

Also worth observing is the 2090 calendar (Su,Su). Why?  Because we don't see it again until 2102 which is 12 years later.  This increases the maximum number between non-leap year calendars I had previously guessed by 1.  So, it would appear that the answers to #4 and #5 are the same.  

So, my answers for this riddle are as follows. 
  1. 14
  2. 2026
  3. 6
  4. 12
  5. 12
  6. 40
As always, it is very possible that I've missed something. Please chime in if I have. 

No comments:

Post a Comment