Skip to main content

Doomsday rule

Last updated: Mar 31, 2023 ·
Posted in wiki#notes

Overview

The Doomsday rule is an algorithm devised by John Conway to quickly calculate the weekday of any date in history. The algorithm works on the following principle:

There is a set of dates (called doomsdays), that for any year, fall on the same weekday (called the anchor day of the year).

Using the anchor, we can find out the weekday for any date using simple arithmetic.

The doomsdays we need to remember in order to use the algorithm are:

MM/DDFull dateMnemonic
1/3 (1/4 for leap years)Jan 3 / Jan 4-
2/28 (2/29 for leap years)Feb 28 / Feb 29-
3/14Mar 14Pi day
4/4, 6/6, 8/8, 10/10, 12/12April 4, Jun 6, Aug 8, Oct 10, Dec 12Even months except Feb
5/9, 9/5, 7/11, 11/7May 9, Sept 5, Jul 11, Nov 79-to-5 at 7-11

Other memorable doomsdays are Jul 4 (Independence day), Oct 31 (Halloween) and Dec 26 (Boxing day).

In total, there are 52 doomsdays in a year. In leap years, the doomsdays in the month of January and February are shifted by one day. However, the total remains the same.

The algorithm involves the following steps.

  1. Find the anchor day for the century (required for step 2).
  2. Find the anchor day for the year. All doomsdays fall on this anchor day.
  3. Count forward/backward from the nearest doomsday to the specified date.

For calculations, we assign an index for each weekday. Starting from Monday (1) to Sunday (7), the index equals rankmod7rank\mod 7.

DayIndexMnemonic
Monday1One-day
Tuesday2Twos-day
Wednesday3Threes-day (Holding up three fingers makes a W)
Thursday4Fours-day
Friday5Five-day
Saturday6Sixtur-day
Sunday0None-day

Example (Jul 27, 1987)

This example shows how the algorithm works in practice. See the sections below for details about step 1 and 2.

  1. Anchor day for the century (1900s) = 3 (Wednesday)

  2. Anchor day for the year (1987) = 6 (Saturday)

  3. Nearest doomsday to Jul 27 is Jul 11 = Saturday (from step 2).

    July 25 = July 11+7+7 = Saturday

    July 27 = Monday.

Finding the anchor day for the century

Given a year yy,

Let cc = the first 2 digits of the year (or y100\left\lfloor\frac{y}{100}\right\rfloor)

Method 1

Anchor = 5×(cmod4)mod75\times(c\mod 4)\mod 7 + Tuesday

Method 2

Value of cmod4c\mod 4Anchor
0Tuesday
1Sunday
2Friday
3Wednesday

Example (1900s)

19mod419\mod 4 = 33     \implies Wednesday

Or

5×(19mod4)mod75\times(19\mod 4)\mod 7 + Tuesday = 11 + Tuesday = Wednesday

The following table lists the anchor days for 1500s to 2600s:

CenturyAnchor day (Index)
1500s, 1900s, 2300sWednesday (3)
1600s, 2000s, 2400sTuesday (2)
1700s, 2100s, 2500sSunday (0)
1800s, 2200s, 2600sFriday (5)

Mnemonics for recent centuries:

  • 1900s: We-in-dis-day (most living people were born in that century)
  • 2000s: Twos-day or Y-Tue-K

Finding the anchor day for the year

Given a year XXYYXXYY,

Method 1

Let aa = Anchor day of the century

b=YY12b = \left\lfloor\frac{YY}{12}\right\rfloor

c=YYmod12c = YY\mod 12

d=c4d = \left\lfloor\frac{c}{4}\right\rfloor

Anchor day of the year = (a+b+c+d)mod7(a+b+c+d)\mod 7

Note: If you use this method, you can store the values for aa, bb, cc, and dd in your index, middle, and ring fingers and the pinkie respectively during mental calculations.

Method 2

Anchor = Century's anchor day + (YY+YY4)mod7\left(YY+\left\lfloor\frac{YY}{4}\right\rfloor\right)\mod 7

Method 3: The "odd+11" method

  1. Let t=YYt = YY
  2. If tt is odd, add 1111.
  3. t=t2t = \frac{t}{2}
  4. If tt is odd, add 1111.
  5. t=7(tmod7)t = 7-(t\mod 7)
  6. Count forward tt days from the century's anchor day to get the year's anchor day.

Note: Each common year advances the anchor day by one day. Each leap year advances it by two days.

Example (1987)

a=3a = 3

b=8712=7b = \left\lfloor\frac{87}{12}\right\rfloor = 7

c=87mod12=3c = 87\mod 12 = 3

d=34=0d = \left\lfloor\frac{3}{4}\right\rfloor = 0

Anchor = (3+7+3+0)mod7=13mod7=6(3+7+3+0)\mod 7 = 13\mod 7 = 6 (Saturday)

Or using "odd+11" method:

8787 -> 9898 -> 4949 -> 6060 -> 7(60mod7)7-(60\mod 7) = 747-4 = 33 -> Wednesday + 3 = Saturday

Example walkthrough (March 19, 1881)

Here's a detailed walkthrough of another example using my preferred methods.

  1. Anchor for 1800s:

    Using method 2 from above, 18mod418\mod 4 = 2    2\implies Friday (5)

  2. Anchor for 1881:

    Using "odd+11" method, 8181 -> 9292 -> 4646 -> 7(46mod7)7 - (46\mod 7) = 33 -> 33 + Friday = Monday (1)

  3. Nearest doomsday to March 19 is Pi day (March 14).

    Since March 14 is a Monday, March 19 must be a Saturday.

Further reading