Monday, 08 August, 2005

Now what day is that?

In the chapter on remembering numbers, the authors of The Complete Idiot's Guide to Improving Your Memory provide an interesting use for memorizing a 12-digit number:  a "first Sundays" list.  The idea is that if you remember the day of the first Sunday in each month, then you can easily determine which day a particular date is on.  For example, this year the first Sunday in October is on the 2nd.  If I wanted to figure out what day my birthday (October 27) lands on, all I have to do is start adding weeks.  The second Sunday is the 9th, then the 16th, and 23rd.  Four days later is the 27th.  So my birthday is on Thursday this year.

That's a pretty cool trick, but I'd have to memorize a first Sundays list for each year.  Taking into account leap years, there are 14 possible 12-digit numbers that I'd have to memorize.  And then I'd have to remember which one goes with which year.  That seems like way too much work.  There is a better solution.

If you know what day is the first Sunday of January, then you can easily compute the first Sunday of each month by memorizing only two 12-digit numbers:  one for leap years and one for non-leap years.  The concept is very simple:  you know that if the first Sunday in January is the 2nd, then the first Sunday in February will be the 6th.  Every time.  And if January 4th is the first Sunday in the year, then February 1 will be Sunday.  If you know the first Sunday of the year and whether or not it's a leap year, then you can determine all of the other first Sundays by simple modulo-7 arithmetic.

Below are the first Sundays lists for 2004 (leap year) and 2005 (not a leap year).  The first number for each month is the date of the first Sunday in that month.  The second number is the offset from the first Sunday in January.  I'll explain below how to use the offset.

Month20042005
Jan4/02/0
Feb1/46/4
Mar7/36/4
Apr4/03/1
May2/51/6
Jun6/25/3
Jul4/03/1
Aug1/47/5
Sep5/14/2
Oct3/62/0
Nov7/36/4
Dec5/14/2

In 2004 the first Sunday in March fell on the 7th, as shown in the table.  You get 7 by adding 3 to the first Sunday of January (the 4th).  This gets a little tricky with February, for example, when the first Sunday was the 1st.  What do you add to 4 in order to get 1?  You add 4, of course, and then divide by 7 and take the remainder.  That is, 4+4 = 8.  Divided by 7 gives you a remainder of 1.

In order to calculate the first Sundays in any year, then, you need to memorize the offsets (the numbers after the slash) in the table above for each month.  Then, if you know the first Sunday of January, you can easily determine the first Sunday of any month in the year.  If you're willing to remember one other rule, all you have to memorize is one 12-digit number.  The rule is:  if it's a leap year, then subtract one from the offset for each month after March.  Take a look at the offsets:

Normal Year:0 4 4 1 6 3 1 5 2 0 4 2
Leap Year:0 4 3 0 5 2 0 4 1 6 3 1

For months after February, the offsets for the leap year are one less than the offsets for the normal year.

I'll leave the memorization of the number 044163152042 as an exercise for the reader.  You might want to consider remembering "January 0, February 4, March 4, April 1, May 6, etc."  That way you can go straight to a particular month without having to scroll through the digits in your head.

Update 08/09:  Something else I realized while I was experimenting with this technique is that you can use it to work backwards to the first Sunday in January.  For example, today is Tuesday, August 9.  So Sunday was the 7th--the first Sunday in the month.  I know from the memorized table of offsets that I add 5 to the date of the first Sunday in January to get the first Sunday in August.  So if I subtract 5 from the first Sunday in August I end up with the first Sunday in January--the 2nd.  From there I can just use the system as described above.

The result is that you don't need to remember the first Sunday of the year.  All you have to remember is the offset table and the "subtract one" rule for leap years.

And one more thing:  That all works fine for the current year, but what about next year?  Last year?  10 years from now?  It's a little more difficult to do in your head, but the idea is simple.  In a normal (i.e. non-leap) year, the first Sunday of next year is the day before the first Sunday this year.  So, for example, this year the first Sunday fell on January 2.  Next year it's January 1.  In a leap year, the first Sunday of the next year is two days prior.  In 2004, the first Sunday was January 4.  So to compute the first Sunday for the year 2009, you would do the successive subtractions:

First Sunday of 2005 is January 2
subtract one to get the first Sunday of 2006:  January 1
subtract one to get the first Sunday of 2007: January 7  (a little modulo-7 arithmetic there)
subtract one to get the first Sunday of 2008: January 6
subtract two (2008 is a leap year) to get the first Sunday of 2009: January 4

Working backwards is similar, but you add.  And remember on leap years you add going into the year (i.e. from 2009 to 2008, you add two).

By the way, that technique works for computing the day of the week for any date, but the leap year rule is applied differently depending on whether the date is before or after March 1.