TOPICS
Search

Doomsday Algorithm


The doomsday algorithm is a mental algorithm for finding the day of the week of a given date by first finding the weekday of the last day of February, called that year's doomsday (Conway 1973, pp. 28-29; Numberphile 2021). It is a specialized method of calendar arithmetic for weekday calculations. The following form uses the Gregorian calendar for every positive-numbered year. Encode Sunday through Saturday by 0 through 6.

Write the positive integer year as Y=100C+y, where C and y are nonnegative integers and y<100. The century anchor A takes the values 2, 0, 5, 3 when the remainder of C upon integer division by 4 is 0, 1, 2, 3, respectively. Set q=|_y/12_| and r=y-12q, where |_x_| is the floor function. The doomsday weekday is

 D=mod(A+q+r+|_r/4_|,7),

where mod selects the remainder from 0 through 6 (Conway 1973, p. 29).

A Gregorian year is a leap year iff its number is a multiple of 4 and is either not a multiple of 100 or is a multiple of 400. February then has 29 days instead of 28 (Dershowitz and Reingold 1990, p. 903).

Dates on doomsday include January 3 (January 4 in a leap year), the last day of February, March 7, April 4, May 9, June 6, July 11, August 8, September 5, October 10, November 7, and December 12. Count forward or backward from one of these dates, using modular arithmetic with modulus 7, to obtain the weekday of the desired date (Conway 1973, p. 29).


See also

Calendar Arithmetic, Modular Arithmetic

Explore with Wolfram|Alpha

References

Conway, J. H. "Tomorrow Is the Day After Doomsday." Eureka 36, 28-31, 1973. https://web.archive.org/web/20240120043257id_/https://www.archim.org.uk/eureka/archive/Eureka-36.pdf.Dershowitz, N. and Reingold, E. M. "Calendrical Calculations." Softw. Pract. Exper. 20, 899-928, 1990. https://doi.org/10.1002/spe.4380200905.Numberphile. "The Doomsday Algorithm." Oct. 31, 2021. https://www.youtube.com/watch?v=z2x3SSBVGJU.

Cite this as:

Weisstein, Eric W. "Doomsday Algorithm." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/DoomsdayAlgorithm.html

Subject classifications