Mental Math and Calendar Calculations

In this previous post, I recalled a discussion I once had with John Conway about the pros and cons of different systems for mentally calculating the day of the week for any given date. In this post, I’ll present two of the most popular systems for doing this, the “Apocryphal Method” [Note added 5/3/20: In a previous version of this post I called this the Gauss-Zeller algorithm, but its roots go back even further than Gauss] and Conway’s Doomsday Method. I personally use a modified verison of the apocryphal method. I’ll present both systems in a way which allows for a direct comparison of their relative merits and let you, dear reader, decide for yourself which one to learn.

Modular arithmetic

A basic prerequisite for understanding these two algorithms is a rudimentary knowledge of modular arithmetic. When we do arithmetic modulo m, it means that we are allowed to add or subtract multiples of m at will without changing the answer. For example, arithmetic modulo 12 is often called clock arithmetic: 13 o’clock is the same as 1 o’clock, so 13 and 1 are congruent modulo 12. Similarly, when we work modulo 12, 5 is congruent to 17, which is also congruent to 29. We can also go backwards: for example, by subtracting 12 we see that 5 is congruent to -7. (This should make intuitive sense: if it’s currently 12 o’clock then in 5 hours it will be 5 o’clock and 7 hours ago it was also 5 o’clock.)

For calendar calculations, we need to work modulo 7 (because there are 7 days of the week) and modulo 4 (because every 4 years there is a leap year). So, for example, when working modulo 7 we find that 37 is congruent to 2, since 35 is a multiple of 7 and 37 – 35 = 2. (One way to think of this is that 2 is the remainder when we divide 37 by 7.) And when we work modulo 4, 19 is congruent to 3 (since we get a remainder of 3 when dividing 19 by 4).

One of the great things about modular arithmetic is that it doesn’t matter if you first add and then simplify things modulo m, or if you simplify along the way. For example, to compute 4+8+11 modulo 7 you could either compute 4+8+11=23 and then simplify to get 23 = 2 (modulo 7), or you could do 4+8 = 12 = 5 (modulo 7) and then add 11 to get 5+11 = 16 = 2 (modulo 7). Or you could recognize that 11 = 4 (modulo 7) and instead of adding 11, just add 4 to get 5+4 = 9 = 2 (modulo 7). See? It doesn’t matter.

Encoding the days of the week

For both the apocryphal and Doomsday methods, we will use the following numerical encoding of the days of the week:

• Sunday = 0
• Monday = 1
• Tuesday = 2
• Wednesday = 3
• Thursday = 4
• Friday = 5
• Saturday = 6

It’s best to memorize this correspondence, not just have the ability to figure it out.

John Conway suggests, as a mnemonic device, thinking of the days of the week as “Noneday”, “Oneday”, “Twosday”, “Treblesday”, “Foursday”, “Fiveday”, and “Six-a-day”.

Also, in the calculations which follow, it’s best to think of these numerical values as being defined modulo 7. So, for example, 3 days after Saturday is a Tuesday, and 6 (Saturday) + 3 is equivalent to 2 (Tuesday) modulo 7.

Year code

In both the apocryphal and Doomsday systems, if we write the year in question as CCYY, the last 2 digits YY will determine a Year Code and the first 2 digits CC will determine a Century Adjustment. The year code, which is the same in both systems, is the most complicated of all the calculations we need to do, so we may as well begin by tackling it head-on.

To find the year code, we first calculate the number of times 4 goes into YY, throwing out any remainder. We then add this result to YY and take the result modulo 7; this gives the year code. (In mathematical terms: the year code is equal to $YY + \lfloor YY / 4 \rfloor$ modulo 7.)

For example, if the year is 1963 then CC = 19 and YY = 63. We calculate:

• 63 divided by 4 is 15 with a remainder of 3 (we ignore the remainder).
• 63 + 15 = 78.
• 78 is congruent to 1 modulo 7, so the year code is 1.

In practice, there are several ways of simplifying or speeding up the calculation of the year code. We explain one now, and discuss some others at the end of this post.

Within any given century, the Gregorian calendar repeats every 28 years. This means that we can subtract multiples of 28 from YY (as long as it doesn’t yield a negative answer) and the result will be the same. To do this quickly, I find the following rules useful:

• To subtract 28, subtract 30 and then add 2.
• To subtract 56, subtract 60 and then add 4.
• To subtract 84, subtract 90 and then add 6.

(In case it helps, note that in each case the number you add is the number of 15’s you subtracted; for example, 60 = 4 * 15.)

So another way to calculate the year code for 1963 would be to do the following:

• YY=63.
• 63 – 60 + 4 = 7.
• 7 divided by 4 is 1 with a remainder of 3 (ignore the remainder).
• 7 + 1 = 8.
• 8 is congruent to 1 modulo 7, so the year code is 1.

Century Adjustment

The Gregorian calendar repeats every 400 years. As a result, the Century Adjustment just depends on CC modulo 4. Specifically:

Apocryphal system

Mnemonics: 31 & -12 (31 = # of days in a typical month, 12 = # of months in a year)

Formula: Century Adjustment = 5*CC – 2 (modulo 7)

You can remember 6 and 5 instead of -1 and -2, if you prefer, since they’re the same modulo 7.

Doomsday system

Mnemonics: If you’re familiar with the Major System, you can easily remember “0532” using the mnemonic “Solomon”. Conway rephrases the Century Adjustments in terms of what he calls “Anchor Days”, and he has mnemonics for these which you can read about here.

If you already know the apocryphal method century adjustments then you can just add 4 (modulo 7) to get the corresponding Doomsday adjustments.

Formula: Century Adjustment = 5*CC – 5 (modulo 7)

Apocryphal algorithm

In the apocryphal system, each month has a month code, given as follows:

The asterisks are there because if the year in question is a leap year, we need to subtract 1 from the month code in January or February.

A good mnemonic for this is that, reading down the list, we have the sequences 144, 025, 036, 146. The first three of these (144, 025, 036) are perfect squares (and the last triad consists of the first 2 digits and the last digit of the previous 9 numbers).

However, if you want to get really fast with the apocryphal system, then just like with the days of the week you’ll need to be able to immediately recall the month code given a month without just “going down the list”. I myself simply memorized the month codes through repetition and drilling, but if you prefer mnemonics, I came up with the following:

• January = 1 (1st month of the year)
• February = 4 (“Fourbruary”)
• March = 4 (There are 4 March sisters in “Little Women”)
• April = 0 (Fools know nothing)
• May = 2 (MAYDAY has two syllables)
• June = 5 (June’s birth stone is PEARL, which has 5 letters)
• July = 0 (America turned 0 in the month of July)
• August = 3 (Augustus Caesar was part of a triumvirate)
• September = 6 (September=Six)
• October = 1 (October=One)
• November = 4 (NOVA has 4 letters)
• December = 6 (Christmas is 6 days from the end of the year)

Apocryphal formula: Day of the Week = Month code + Day + Year Code + Century Adjustment (modulo 7).

Example 1: April 14, 1963

• Month code = 0
• Day = 14 (= 0 modulo 7)
• Year code = 63 + 15 = 78 (= 1 modulo 7)
• Century adjustment = -1 (since 19 = 3 modulo 4)
• Day of the week = 0 + 0 + 1 – 1 = 0 <—> Sunday

Example 2: March 9, 1840

• Month code = 4 (no leap year adjustment)
• Day = 9 (= 2 modulo 7)
• Year code = 40 + 10 = 50 (= 1 modulo 7)
• Century adjustment = 1 (since 18 = 2 modulo 4)
• Day of the week = 4 + 2 + 1 + 1 = 1 (modulo 7) <–> Monday

Example 3: February 25, 2016

• Month code = 4 – 1 = 3 (-1 for the leap year adjustment)
• Day = 25 (= 4 modulo 7)
• Year code = 16 + 4 = 20 (= 6 modulo 7)
• Century adjustment = -2 (since 20 = 0 modulo 4)
• Day of the week = 3 + 4 + 6 – 2 = 11 = 4 modulo 7 <–> Thursday

Conway’s Doomsday algorithm

In Conway’s method, instead of memorizing a code for each month we memorize certain dates, called Doomsdays, which always fall on the same day of the week in any given year. We use the year code and century adjustment to figure out what day of the week Doomsday is in the given year, and then we adjust forward or backward from the appropriate Doomsday to figure out the day of the week for the given date.

Some dates which fall on Doomsday:

• 1/3*, 2/28*, 3/14 (Mnemonic: Pi = 3.14)
• 4/4, 6/6, 8/8, 10/10, 12/12
• 5/9, 9/5, 7/11, 11/7 (Mnemonic: “Working 9 to 5 at the 7-Eleven”)

One of the great things about Conway’s algorithm is how easy it is to memorize this list!

The asterisks are there because in a leap year, Doomsday will be 1/4 rather than 1/3 and 2/29 instead of 2/28. As a mnemonic for these, Conway suggests remembering that for January it’s the third day 3 years out of 4, and the fourth day every 4th year. And Doomsday is always the last day in February.

Doomsday rule: Day of the week for Doomsday = Year Code + Century Adjustment (modulo 7)

In the following examples, we use the “multiples of 28” simplification when calculating the year code.

Example 1: April 14, 1963

• YY = 63 (= 63 – 60 + 4 = 7 modulo 28)
• Year code = 7 + 1 = 8 (= 1 modulo 7)
• Century adjustment = 3 (since 19 = 3 modulo 4)
• Year code + Century adjustment = 1 + 3 = 4 <—> Thursday. So Doomsday was a Thursday in 1963. But it’s better to just remember the number 4, rather than convert it right now to Thursday.
• Closest reference Doomsday = 4/4. Since 4/4 was a Thursday, 4/14 was a Sunday (4 + 10 = 14 = 0 modulo 7).

Example 2: March 9, 1840

• YY = 40 (= 40 – 30 + 2 = 12 modulo 28)
• Year code = 12 + 3 = 15 (= 1 modulo 7)
• Century adjustment = 5 (since 18 = 2 modulo 4)
• Year code + Century adjustment = 1 +5 = 6 <—> Saturday. Remember the number 6.
• Closest reference Doomsday = 3/14. So 3/9 was a Monday (6 – 5 = 1 modulo 7).

Example 3: February 25, 2016

• YY = 16
• Year code = 16 + 4 = 20 (= 6 modulo 7)
• Century adjustment = 2 (since 20 = 0 modulo 4)
• Year code + Century adjustment = 6 +2 = 8 (= 1 modulo 7) <—> Monday. Remember the number 1.
• Closest reference Doomsday = 2/29 (leap year adjustment). So 2/25 was a Thursday (1 – 4 = -3 = 4 modulo 7).

A note on leap years

In order to correctly identify days of the week in years such as 1900 or 2000 which are divisible by 100, it is necessary to understand the lesser-known quirks of the Gregorian calendar. (For the purpose of our calendar calculations, this only affects dates in January and February.)

The general rule for leap years is: every year divisible by 4 is a leap year, unless that year is divisible by 100 but not by 400. So, for example, 1900 was not a leap year, but 2000 was.

Example 1: January 30, 1900

Apocryphal method: Year code = 0, Century adjustment = -1, Month code = 1 (don’t subtract 1 as we would in a leap year), Day = 30.

0 – 1 + 1 + 30 = 2 (modulo 7) <—> Tuesday

Doomsday method: Year code = 0, Century adjustment = 3, so Doomsday was a Wednesday in 1900. Closest Doomsday = Jan. 3 (since 1900 isn’t a leap year), so January 30 (27 = 28 – 1 days later) was a Tuesday.

Example 2: January 30, 2000

Apocryphal method: Year code = 0, Century adjustment = -2, Month code = 0 (subtract 1 for the leap year), Day = 30.

0 – 2 + 0 + 30 = 0 (modulo 7) <—> Sunday

Doomsday method: Year code = 0, Century adjustment = 2, so Doomsday was a Tuesday in 1900. Closest Doomsday = Jan. 4 (since 2000 is a leap year), so January 30 (26 = 28 – 2 days later) was a Sunday.

A trick question

George Washington was born on February 11, 1731. What day of the week was this?

If we follow our method, we get the (incorrect) answer Sunday.

The problem is that England and its colonies did not adopt the Gregorian calendar until 1752; the Feb. 11, 1731 date is from the Julian calendar. In the Gregorian calendar, George Washington was born on Feb. 22, 1732, which was a Friday (the correct answer).

Alternate methods for arriving at the year code

Calculating the year code in a speedy manner is one of the primary barriers to a quick execution of either of the two systems we’ve been discussing. Here are a few alternate methods which have been proposed (see this Wikipedia page for references):

• Lewis Carroll’s method: Divide YY by 12; say it goes in A times with a remainder of B. Let C be the number of times 4 goes into B (throwing out the remainder). Then the year code is A+B+C (modulo 7). (In Conway’s own prose, you add together: “The number of dozens; the remainder after this; and the number of 4’s in the remainder.”) For example, if YY=63 then A=5, B=3, C=0 and the year code is 5+3+0 = 1 (modulo 7), and if YY=16 then A=1, B=4, C=1 and the year code is 1+4+1 = 6 (modulo 7).
• Mike Walters’s “Easy Doomsday” method: If YY is not already a multiple of 4, add 11, 22, or 33 according to whether YY modulo 4 is 1, 2, or 3. Now divide by 2, take the result modulo 7, and subtract from 7 to get the year code. For example, if YY=63 then we add 33 to get 96, divide by 2 to get 48, and take this modulo 7 to get 6. Subtracting from 7 gives 7 – 6 = 1 for the year code. And if YY=16 then we divide by 2 to get 8, which is congruent to 1 modulo 7. Subtracting from 7 gives 7 – 1 = 6 for the year code.
• The “Odd + 11” method (a modification of the “Easy Doomsday” method due to Fong and Walters): If YY is odd, add 11 and divide by 2; otherwise just divide by 2. If the new number is odd, add 11; otherwise do nothing. Take the resulting modulo 7 and subtract from 7 to get the year code. For example, if YY=63 then we add 11 to get 74 and divide by 2 to get 37. Adding 11 gives 48, which is 6 modulo 7, giving 7 – 6 = 1 as the year code. And if YY=16 then we divide by 2 to get 8, which is congruent to 1 modulo 7. Subtracting from 7 gives 7 – 1 = 6 for the year code.

Other mental shortcuts

As with solving a Rubik’s cube, the best way (other than frequent practice and repetition) to improve one’s ability to quickly perform mental calendar calculations is to learn additional shortcuts. For example, to speed up the Doomsday method it is useful to learn additional dates, besides the ones listed above, which always fall on a Doomsday. Additional easy-to-remember examples include July 4th and October 31 (Halloween). The more of these you know (without having to think about it), the faster you’ll get at the Doomsday method. You can find a complete list of Doomsdays here.

For the year code, one can avoid excessive calculations by memorizing the year code for a number of target years and then just working backward or forward from these. For example, suppose you manage to memorize the following two lists:

Year Code 0: 00, 06, 17, 23

Year Code 3: 03, 08, 14, 25

Then you can get to any year by first subtracting multiples of 28 from YY to get into the range 00 through 27, then counting up or down at most 3 years from one of the reference years (taking leap years into account as appropriate). For example:

• YY = 78 ==> 78 – 60 + 4 = 22, which is one less than 23, so the year code for ’78 is 0-1=6.
• YY = 52 ==> 52 – 30 + 2 = 24, which is 1 more than 23. Since years ending with 24 are leap years, we have to add 2 (not 1) to get the year code for ’24 from that of ’23. So the year code for ’52 is 0+2=2.
• YY = 94 ==> 94 – 90 + 6 = 10, which is 2 more than 08. Since we don’t move through any leap years when going from ’08 to ’10, we add 2 to the year code for ’08 to get a year code of 3+2=5 for ’94.

Of course, you could go even further and memorize all the years with year code 0 (00, 06, 17, 23, 28, 34, 45, 51, 56, 62, 73, 79, 84, 90). The mnemonics I personally use for this are:

• 00, 28, 56, 84: multiples of 28
• 1906: SF Earthquake
• 1917: US enters WW1; 1945: WW2 ends
• 1951: Rosenbergs executed; 1962: Cuban Missile Crisis
• 1973: Roe v. Wade (also my birth year)
• 1979: Russia invades Afghanistan; 1990: Iraq invades Kuwait

(This leaves just 23 & 34, which I remember in terms of the numerical patterns.)

If you also memorize 03, 08, 14, 31, 36, 42, 64, 70, 92, 98 as having year code 3, then you can get to any given year from a reference year with code 0 or 3 by counting up or down at most 3 years. If you can master the memorization required, this method is significantly faster than calculating the year code with a formula. Here are some mnemonics (I use famous dates in the 1900’s for year code 0 and famous dates in the 1800’s for year code 3):

• 1803: Louisiana Purchase
• 1808: African slave trade ended in U.S.
• 1814: White House burned down by British troops
• 1831: Nat Turner’s rebellion
• 1836: Battle of the Alamo
• 1864: General Sherman burns down Atlanta
• 1870: Franco-Prussian War
• 1898: Treat of Paris signed, ending the Spanish-American War

(This leaves just 42 and 92, which can be remembered separately).

If you don’t know these dates already, your trivia skills will improve by learning them regardless of whether or not you use them for calendar calculations.

Comparing the two methods

Returning to the beginning of this post (where I recalled my own conversation with Conway on this topic): how do these two methods compare?

Well, in a nutshell I personally think that the apocryphal method is simpler once you buckle down and memorize the month codes. If you’re good at doing arithmetic modulo 7 in your head, then the only real bottleneck for speed is determining the year code (which is common to both methods).

On the other hand, the (basic) Doomsdays are easier to remember than the month codes, thanks to Conway’s nifty mnemonics. And if you commit additional Doomsdays to memory, it will speed things up accordingly (the apocryphal method does not admit such added flexibility).

Conway’s method can be explained in more elementary terms, since one doesn’t really have to know modular arithmetic to understand the method. Combined with the fact that the basic Doomsdays are so easily memorized, this provides a strong pedagogical argument on behalf of Conway’s method. On the other hand, I actually teach modular arithmetic in my Number Theory course using calendar calculations, and the apocryphal method is a perfect illustration its application to real-life problems (the circle of fifths in music theory being another).

An alternate way of coding the days of the week

In reality, I use a slightly different encoding for the days of the week than what I explained above. (I learned this from the book “Mathematical Magic” by William Simon when I was a kid.) The correspondence I use is:

• Saturday = 0
• Sunday = 1
• Monday = 2
• Tuesday = 3
• Wednesday = 4
• Thursday = 5
• Friday = 6

(For me this is natural, because I’m Jewish and instead of the seventh day (Sabbath = Day of Rest) being Sunday, in my system it’s Saturday. 😊 )

If you use this correspondence, the only modification necessary for the apocryphal method, as described above, is to add 1 (modulo 7) to the century adjustment. So instead of

3 1 -1 -2,

I use

4 2 0 -1.

One advantage of this encoding is that for dates in the 20th century (which is when I learned the system), no century adjustment is needed (i.e., the Century Adjustment for 19** is 0).

If you wish to use this encoding of days of the week with the Doomsday method, again the only necessary adjustment is to add 1 (modulo 7) to the Century Adjustment. So instead of

0 5 3 2,

we get the modified Century Adjustments

+1 -1 +4 -4,

which is rather easy to remember.

A challenge problem

Use either of the above systems to solve the following problem:

On what day of the week is the 13th day of the month most likely to fall?

Parting thoughts

If you learn either of these methods and incorporate some of the tips I’ve given here, you’ll find that with practice you can calculate the day of the week for any given date quite rapidly. To achieve Conway-like proficiency, though, will take incredible dedication.

When the New York Times profiled John Conway in this 1993 piece by Gina Kolata, the article began:

DR. JOHN H. CONWAY sits down at his computer and gets ready to log on. But before the computer allows him to begin work, it quickly spews out 10 randomly selected dates from the past and the future, dates like 3/15/ 2005 or 4/29/1803. Dr. Conway has to mentally calculate what day of the week each would be before his computer lets him open a file and get to work.

It is a game he has rigged up to play with himself. “I think I’m the fastest person in the world at this,” he says. His record is 15.92 seconds to calculate all 10 days.

References

For more information, see the following sources:

14 thoughts on “Mental Math and Calendar Calculations”

1. Chamberlain says:

Great post! One minor correction: The method for calculating the year code using a divide by 12 is not Conway’s method. This actually came from Lewis Carroll. See Martin Gardner’s “Trick of Lightning Calculators” in his May 1967 Scientific American column to fact check this. The article is reprinted in Gardner’s book “Mathematical Carnival”. You can also read about Lewis Carroll’s method in the book “The Universe in a Handkerchief” by Gardner.

Reply
• Thanks, Chamberlain. I just corrected this attribution in the post!

Reply
2. Chamberlain says:

One side-note on mental math:

I often get the question: “Why bother with mental math in the age of the smartphone?”. To which my response is “For the same reason that people still jog and run in the age of automobile.” While running helps in maintaining physical health, mental math helps in maintaining mental health. Doing mental calculations can help stave off dementia and Alzheimer’s disease.

Reply
• Nice analogy, Chamberlain. And mental math aficionados train to improve their speed for pretty much the same reason that runners do. (To win endorsements and prize money – just kidding).

Reply
3. Are you familiar with C.H. Wilson’s method, from his 1877 book “52 Wonders”? At the time it was published, it was the first method in print (Gauss’s method, derived earlier, was not published until 1927; Zeller’s and Carroll’s came later).

Reply
4. No, I’m not familiar with it. Is there a modern exposition available somewhere?

Reply
• Hi Bill – I found out from Tyler Wilson that he now knows about published methods even older than C.H. Wilson’s! In fact, at least one of these predates Gauss’s own derivation. I will add some historical remarks to my next blog post.

Reply
5. Chamberlain says:

Nice meta Monday follow-up on calendar calculations.

In light of the ongoing pandemic and the reboot of 2020, I’d like to mention Jakow Trachtenberg (1888-1953). He developed his Trachtenberg system for rapid mental calculation while being imprisoned in Nazi concentration camp!

Trachtenberg’s life and achievements is a testament on how mental math can help keep you sane and preoccupied during challenging times. We all need some sort of preoccupation while waiting for the great reboot…

Reply
• Fascinating… thanks, Chamberlain! I knew nothing about this.

Reply
6. First of all ,thanks for sharing this article. you explained it very well and i learn so many things from this article. i wish you will post more article just like this one

Reply