Doomsday rule

From Free net encyclopedia

The doomsday rule or doomsday algorithm is a way of calculating the day of the week of a given date. It is perpetually accurate since the Gregorian calendar moves in cycles of 400 years. It makes use of the fact that, in each year, certain dates are all on the same day of the week.

The algorithm was invented by John Horton Conway. It takes advantage of the fact that within any calendar year, the days of 4/4, 6/6, 8/8, 10/10 and 12/12 always occur on the same day of week. That day of week is called Doomsday. This applies to both the Gregorian Calendar A.D. and the Julian Calendar, but note that Julian calendar Doomsdays usually occur on different days from the Gregorian calendar Doomsdays.

Contents

The algorithm

The algorithm has three steps, namely, finding the anchor day for the century, finding a year's doomsday, and finding the day of week of the day in question.

Let us speed up the process of finding the anchor day for the century. Remember, for the purposes of the Doomsday rule, a century starts with a "00" year and ends with a "99" year.

Century Anchor day Mnemonic
1800-1899 Friday
1900-1999 Wednesday "We-in-dis-day"
(most of us were born in that century)
2000-2099 Tuesday "Y-Tue-K"
(Y2K was at the head of this century)
2100-2199 Sunday

Next, it is necessary to find the year's Doomsday—the day of the week on which the last day of February falls. To accomplish that according to Conway, begin by dividing the year's last two digits (call this y) by 12 and taking the integral value of the quotient (a). Then take the remainder of the same quotient (b). After that, divide that remainder by 4 and take the integral value (c). Finally, determine the sum of the three numbers (add a, b, and c to get d). (It is again possible here to divide by seven and take the remainder. This number is equivalent, as it must be, to the sum of the last two digits of the year plus the integral value those digits divided by four.)
Now count forward the specified number of days (d or the remainder of d/7) from the anchor day to get the year's Doomsday.
<math>\left({\left\lfloor{\frac{y}{12}}\right\rfloor+y \bmod 12+\left\lfloor{\frac{y \bmod 12}{4}}\right\rfloor}\right) \bmod 7+\rm{anchor}=\rm{Doomsday}</math>

For the twentieth-century year 1966, for example:
<math>\begin{matrix}\left({\left\lfloor{\frac{66}{12}}\right\rfloor+66 \bmod 12+\left\lfloor{\frac{66 \bmod 12}{4}}\right\rfloor}\right) \bmod 7+\rm{Wednesday} & = & \left(5+6+1\right) \bmod 7+\rm{Wednesday} \\ \ & = & \rm{Monday}\end{matrix}</math>
So Doomsday in 1966 fell on Monday.

Similarly, Doomsday in 2005 is on a Monday:
<math>\left({\left\lfloor{\frac{5}{12}}\right\rfloor+5 \bmod 12+\left\lfloor{\frac{5 \bmod 12}{4}}\right\rfloor}\right) \bmod 7+\rm{Tuesday}=\rm{Monday}</math>

The following days all occur on Doomsday for any given Gregorian year:

The dates listed above were chosen to be easy to remember; the ones for even months are simply doubles, 4/4, 6/6, 8/8, 10/10, and 12/12. Four of the odd month dates (5/9, 9/5, 7/11, and 11/7) are recalled using the mnemonic "I work from 9 to 5 at the 7-11."

For dates in March, March 7 falls on Doomsday, but the pseudodate "March 0" is easier to remember, as it is necessarily the same as the last day of February. Similarly, in leap years the pseudodate "January 32" is easier to remember than January 4, as it is necessarily the same as February 1 (and therefore February 29th).

Therefore, if you know what day of the week Doomsday—the last day in February—is for a given year, you can easily determine the day of the week for any other date in that year, by finding the nearest Doomsday.

The complete list

January (common years) January 3rd, 10th, 17th, 24th, & 31st
January (leap years) January 4th, 11th, 18th, & 25th
February (common years) February 7th, 14th, 21st, & 28th
February (leap years) February 1st, 8th, 15th, 22nd, & 29th
March March 7th, 14th, 21st, & 28th
April April 4th, 11th, 18th, & 25th
May May 2nd, 9th, 16th, 23rd, & 30th
June June 6th, 13th, 20th, & 27th
July July 4th, 11th, 18th, & 25th
August August 1st, 8th, 15th, 22nd, & 29th
September September 5th, 12th, 19th, & 26th
October October 3rd, 10th, 17th, 24th, & 31st
November November 7th, 14th, 21st, & 28th
December December 5th, 12th, 19th, & 26th

In code

The following is the algorithm in C. Note that division in C (using the / operator) is integer division and that the % operator is the modulo operator.

Set "year" to whatever year (this case is 2005) computation is desired and the numeric values of the days of the week are:

0 – Sunday
1 – Monday
2 – Tuesday
3 – Wednesday
4 – Thursday
5 – Friday
6 – Saturday
// Determine the anchor day for the century
year    = 2005;
century = year/100 + 1;
a       = century * 5;
b       = (century - 1) / 4;
c       = a + b;
anchor  = (c + 4) % 7;
// Determine the Doomsday for the year in question
e       = (year % 100)/12;
f       = (year % 100)%12;
g       = f/4;
h       = e + f + g;
dday    = (h + anchor) % 7;

"anchor" is the anchor day for the century and "dday" is the doomsday for the year. If "dday" is found to be Monday, then January 3 (or 4th), February 28 (or 29th), March 0, April 4, May 9, etc. (see above). To find the day of the date in question, determine the number of days away from the doomsday (as a positive value after and a negative before) for that month and add it to "dday" modulo 7.

Correspondence with dominical letter

Doomsday is determined by the dominical letter of the year as follows:

Dominical
letter
Doomsday
A or BATuesday
B or CBMonday
C or DCSunday
D or EDSaturday
E or FEFriday
F or GFThursday
G or AGWednesday

Doomsdays for some contemporary years

Doomsday for the current year (2025): Template:Switch

2003Friday
2004Sunday
2005Monday
2006Tuesday
2007Wednesday
2008Friday
2009Saturday

Examples

Example 1 (this year)

Suppose you want to know which day of the week Christmas Day of 2006 is. In the year 2006, Doomsday is Tuesday. (The century's anchor day is Tuesday, and 2006's Doomsday is seven days beyond and is thus also a Tuesday.) This means that December 12 is a Tuesday. December 25, being thirteen days afterwards, falls on a Monday.

Example 2 (other years of this century)

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

Example 3 (other centuries)

Suppose that you want to find the day of week that the American Civil War broke out at Fort Sumter, which was April 12, 1861. The anchor day is 99 days after Thursday, or Friday. The digits 61 give a displacement of six days, so Doomsday was Thursday. Therefore, April 4 was Thursday, so April 12, eight days later, is a Friday.

Important note

Historically, great effort has been expended to ensure that the Gregorian calendar accurately lines up with astronomical events (such as solstices). The best example of this is the year 1582, when the Gregorian Calendar was first instituted. In order to correct for calendar drift, several days in October were skipped (i.e. there were no dates 5 October - 14 October in that year). Resultantly, the above algorithm will not work for dates prior to 15 October 1582. Care should be taken whenever calculating dates with such a "static" algorithm, due to other minor irregularities in the calendar. Finally, it is important to mention that the Gregorian calendar was not adopted simultaneously in all countries, so for many centuries, different regions used different dates for the same day. More information can be found in the Gregorian Calendar article.

External links

ko:둠스데이 알고리즘