A better way to calculate the day of the week

Look Like a Genius

Calculating the day of the week for historical date is impressive, but it isn’t as hard as it seems. Several methods have been shown to work and be performable by average humans. This is an improvement to one of the simplest methods.

The Doomsday Rule

Paraphrased from wikipedia:

The Doomsday rule or Doomsday algorithm is a relatively simple way to calculate the day of the week of a given date. It was devised by John Conway, drawing inspiration from Lewis Carroll’s work on a perpetual calendar algorithm. The algorithm takes advantage of the fact that several easy-to-remember dates fall on the same day each year; for example, 4/4, 6/6, 8/8, 10/10, 12/12, and the last day of February are all the same day of the week.

Conway’s original algorithm required dividing by 12 and 4, and remembering several intermediate values. It’s achievable, but not simple.

Odd+11

The Odd+11 rule simplifies the math, requiring nothing more than knowing if a number is odd, and adding 11.

The Difficulty

The Doomsday Rule and the Odd+11 update both start with the actual day of the week. From the Wikipedia article:

Suppose that you want to find the day of week that the September 11, 2001 attacks on the World Trade Center occurred. The century anchor was Tuesday, and Doomsday for 2001 is one day beyond, which is Wednesday. September 5 was a Doomsday, and September 11, six days later, fell on a Tuesday.

Having converted to the day of the week, adding numbers to it can be tough — what day of the week is 11 days after a Friday? Further, the methods require remembering the century day while doing the year calculation (per the Wikipedia article), or remembering the century while doing the year calculation and then evaluating the actual day of the week — the doomsday — from both.

Finally, to find the desired date, work theough the weeks mentally (perhaps backwards). This can be simplified by memorizing additional doomsdays. Conway’s mnemonics are very useful, but they only cover one date per month.

The Modification

Instead of starting with a day of the week for the century, this method delays conversion to the day of the week until the last step. Before that, everything is simply in terms of numbers. This avoids having to do week-based calculations, memorizing additional doomsdays, or remembering multiple intermediate steps.

Two variants of the algorithm are given. The first works in the same order as the Conway algorithm, starting from the year and century and then adding in the month and finally subtracting the day. The second algorithm starts with the month, then subtracts the day, then adds in the century and year. This allows the user to process the information in the order that it is ordinarily given: March 23rd, 1974 (a Saturday) — although the algorithm has a few more steps.

Century First

Here is an example for January 18, 1936:

  1. 1900s: start with 8
  2. Add the year: 8 + 36 = 44
  3. 44 is even so don’t add 11
  4. 44/2 = 22
  5. 22 is even  so don’t add 11
  6. Add the month “doomsday” number for January: 22 + 3 = 25
  7. It’s January in a leap year, so 25 + 1 = 26
  8. Subtract the day: 26 – 18 = 8
  9. Take the 7s complement — this is the number of days until the next multiple of 7, which is probably the easiest way to produce it. Technically it is: (7 – 8 mod 7) mod 7 = 6
  10. Convert to a day of the week starting from Sunday = 0, so 6 = Saturday.

Here is a flowchart:

20130409-221650.jpg

Month First

Here is an example for September 16th, 2065:

  1. Start with the month number (the “doomsday” date for the month): September = 5
  2. Subtract the day. 16 > 5, so first add a multiple of 7: 5 + 14 = 19, 19 – 16 = 3
  3. It’s not January or February in a leap year, so don’t add 1
  4. 3 is odd, so: 3 + 7 = 10
  5. 10 * 2 = 20
  6. Add the century number for 2000s: 20 + 24 = 44
  7. Add the year: 44 + 65 = 109
  8. 109 is odd, so: 109 + 11 = 120
  9. 120/2 = 60
  10. 60 is even, so don’t add 11
  11. Take the 7s complement — this is the number of days until the next multiple of 7, which is probably the easiest way to produce it. Technically it is: (7 – 60 mod 7) mod 7 = 3
  12. Convert to a day of the week starting from Sunday = 0, so 3 = Wednesday.

Here is a flowchart:

20130409-221828.jpg

Advertisements

2 thoughts on “A better way to calculate the day of the week

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s