This entry has little to do with programming. However, it deals with something that has proven very useful to me and I don’t want to forget it.

# The guts:

For quick reference, these are the main things to remember to perform the Doomsday Algorithm in your head:

given a date **ccyy/mm/dd:**

- doomsday of a century (
**dcc**) =**10 – 2(cc % 4)** - doomsday of a year (
**dyy**) =**dcc + yy + floor(yy / 4)** - day of month falling on a doomsday = “
**3-2-1**”, “**I work 9-5 at the 7-11**”.

# What does all that mean?

The Doomsday Algorithm is a method developed by Dr. John Horton Conway as a means of quickly being able to determine the day of the week for any day of any month of any year, as well as being the basis for other date calculations, and to be able to do so mentally.

Anyone who knows me will immediately see why I was all over this algorithm when I first heard of it.

Having used the method for a few years now, I have been able to make some improvements and to expand it for more general use.

So what is it? Basically, it starts from a simple premise: if you know the day of the week for one day in a month, you can figure out any other day in the month. It then expands it: if you know one day of the week for one day in the year, you can figure out any other day in the year. And then if you know one day of the week for one day in a century then you can figure out any other day in the century.

How does it work? Lets start from the simplest premise that you know day of the week of one day in the month.

## Knowing one day of the month

This one is pretty easy. Say it is Wednesday, Oct 7. Then obviously Oct 14, 21, and 28 are all Wednesdays. Oct 17 is 3 days past Oct 14 so it is 3 days past Wednesday: Saturday. Pretty basic.

## Knowing one day of the year

The trick now is how do you get the weekday for a day in some arbitrary month. This is the heart of the Doomsday Algorithm.

Doomsday (don’t ask me why ‘doomsday’) refers to the day of the week of the last day in February. If you know this, then you can quickly determine a date in any month of the year that also falls on the Doomsday. An example may help.

Let us say that we are looking for what day Christmas will fall on in 2011. The Doomsday (Feb 28) for 2011 is Monday.

The rules for determining a date that is a Monday for any month in 2011 are:

- Memorize the phases “
**3 for 3 and 4 on the 4t**h” and “**I work 9-5 at the 7-11**”.*Note: “***3 for 3 and 4 on the 4th**” is one my improvements to Dr. Conway’s method. The method, as I originally read it, simply described how to figure out Jan, Feb and Mar, but did not have a mnemonic.

- [edit] After using the “
**3-2-1**” method in the note below for the last few months, I feel it is superior to “**3 for 3 and 4 on the 4th**” method outlined below. So feel free to skip this indented section and just go to the note below.- Jan: “
**3 for 3 and 4 on the 4th**” is a mnemonic to indicate that on non-leap years Jan**3**falls on the Doomsday (Monday), and on leap years Jan**4**th falls on the Doomsday (don’t worry that leap years do not occur every 4 years – just remember 3 for non-leap years, 4 for leap years). - Feb: We already know Feb 28 or 29 (28 in our case) is a Monday.
- Mar: This is the oddball. You can try thinking of March as an extension of February: Feb 28/29 = Mar 0 and continue from there.

- Jan: “
*Note: An alternate mnemonic that I have just started using is “***3–2–1**”. The first digit of this sequence reminds me that Jan**3**is a doomsday as are Feb**21**and Mar**21**. When read backwards, it reminds me that on leap years I should add**1**to the first**2**months and leave the**3**rd month alone (Jan 4, Feb 22 and Mar 21). I’m not sure how successful this method will be, but is easier than remembering 3 different rules for the first 3 months.- Apr: For all other even-numbered months (Apr, Jun, Aug, Oct, Dec) the day of the month that equals the month of year will fall on the Doomsday. April is the
**4**th month so Apr**4**is a Monday. - May: For all other odd-numbered months the mnemonic “
**I work 9-5 at the 7-11**” pairs the month of the year with day of the month that falls on the Doomsday. May is the**5**th month, and**5**is paired with**9**, so May**9**is a Monday. - Jun: See Apr. Jun 6 is a Monday.
- Jul: See May. Jul 11 is a Monday.
- Aug: See Apr. Aug 8 is a Monday.
- Sep: See May. Sep 5 is a Monday.
- Oct: See Apr. Oct 10 is a Monday.
- Nov: See May. Nov 7 is a Monday.
- Dec. See Apr. Dec 12 is Monday.

Now that we know Dec 12 is a Monday, it is a cinch to figure out that Christmas falls on a Sunday.

So now, you can just remember just one day of the year (the Doomsday for the current year) and you are good to go for the whole year.

## Knowing one day in a century

But what if you want to work with other years? What is the Doomsday for 2012? 2068?

To do this you need to know the Doomsday of the century year (the year that ends with 00 – I know, I know: that year belongs to the previous century – but for the purposes of this method the century year for this century is 2000). If you know that 2000 Feb 29 was a Tuesday then you can figure out any day between 2000 Jan 1 and 2099 Dec 31. How? By finding the Doomsday for the year and using the methods presented earlier.

The original method presented by Dr Conway (which you can skip) is:

- Take the year of the century (the last 2 digits) and divide by 12 – remember the integer portion of the result.
- Remember the remainder from above result.
- Divide the remainder by 4 and remember the integer portion of the result.
- Add these 3 numbers together and then add that to Doomsday of the century year. This will give you the Doomsday of the desired year.

I found this cumbersome and dividing by 12 is not conducive to easy mental calculation.

My alternate method is

- Take the year of the century and add the year of the century divided by 4 (dropping the remainder).
- Add the result to the Doomsday of the century year.

Note: feel free to perform modulus 7 operations on any of the results to keep the numbers manageable.

So, for example, Oct 21, 2041:

- Doomsday for 2000 is Tuesday.
- 41 + (41 / 4) = 41 + 10 = 51 = 2 (after modulus 7)
- Doomsday for 2041 is Tuesday + 2 = Thursday
- Oct 10 = Thursday, so Oct 21 = Monday.

So, again, by knowing one day of the century (the Doomsday of the century year), you can figure out any day in that century.

## Knowing one day for any century

So what about other centuries? Do you have to memorize the Doomsday for each century? No.

If you don’t know the Doomsday of the century year, the method presented by Dr Conway requires the use of a table – again not conducive to mental calculation. So I created the following:

- Take the century (the first 2 digits of the year) and modulus with 4.
- Multiply the result by 2 and subtract that from 10.
- Modulus the result with 7 if needed.

The final number is a day of the week with 0 = Saturday, 1 = Sunday… 6 = Friday.

For example, for the 1900’s:

- 10 – 2(19 % 4) = 10 – 2(3) = 4 = Wednesday

# A final example

Everyone’s favourite starship captain is to be born on March 22, 2233.

- Doomsday for the 2200’s = 10 – 2(22 % 4) = 10 – 2(2) = 6 = Friday
- Doomsday for 2233 = Friday + 33 + (33/4) = Friday + 33 + 8 = Friday + 5 + 1 = Thursday
- From “
**3-2-1**” and the fact that 2233 is not a leap-year, March 21 = Thursday

And in case all the mathematical symbols have made you think that you are going to need a spreadsheet, a ream of paper, and the help of your grade-7 child, you don’t. Here’s how I actually do it in my head:

- 22 mod 4 is 2… times 2 is 4… from 10 is
**6** - 33 divided by 4 is 8… plus 33 is 41… plus
**6**is 47… mod 7 is 5, which is**Thursday** - 3-2-1 means March 21 is
**Thursday**, so March 22 is Friday

Captain Kirk will be born on a Friday. What? You thought I meant Picard? Yeah right! As if!

One caveat:

Don’t rely on the Doomsday method for historical dates before the first quarter of the twentieth century. Even though the Gregorian calendar was established in 1582, different countries took their time in adopting it, and there were many revisions and mistakes made along the way (see http://en.wikipedia.org/wiki/Gregorian_calendar). Turkey, for instance, didn’t adopt the Gregorian calendar until 1926.

So if your Doomsday calculation comes up with Friday and the history books say Tuesday, you may want to do some research into the country being referred to and its calendar(s).

For those of you who are wondering about my comment “that leap years do not occur every 4 years”: well they don’t.

Leap years occur every 4 years, except every 100 years, except every 400 years. That is years that are divisible by 100 (like 1900 and 2100) are not leap years (even if Microsoft Excel thinks they are). And years that are divisible by 400 (like 2800 and 2000) are leap years.

This is done because a year is not 365 days long: the mean length of a tropical year (vernal equinox to vernal equinox) is 365.24219 days. If we just added a leap year every four years then our calendar year would average 365.25 days – close, but no cigar.

By taking out leap days every 100 years and adding them back in every 400, we get an average year of 365.2425 days. Close enough to 365.24219 that we can push off the responsibility of what to do with the extra .00031 days (26 seconds a year) to our great-great-great-great-great-great-great-great-great-great-great-great-great-grandchildren to deal with.