
The Doomsday Algorithm - Numberphile
video description
If you know the first day of a given year, you can calculate any other date of that year as follows:
month_mods = [0, 3, 3, 6, 1, - 4, 6, 2, 5, 0, 3, 5] (You would have to memorize these values)
value = first_day_index + month_mods[month_index] + day_index
if (is_leap_year AND month_index > 1) value = value + 1
day = value MOD 7
Example:
21st of July 2084
first_day_index = 6 (Saturday)
month_index = 6 (July)
day_index = 20 (21st day)
value = 6 + 6 + 20 + 1 = 33 (2084 is a leap year and July is after February so we add one to value)
day = 33 MOD 7 = 5 (Friday)
Also an algorithm to determine the first day of a given year (this is bit too complicated to do fast)
t = year - 1
first_day = (1 + t + t / 4 - t / 100 + t / 400) MOD 7
Example:
year = 3981
t = 3980
first_day = (1 + 3980 + 995 - 39 + 9) MOD 7 = 4946 MOD 7 = 4 (Thursday)
1st of January 3981 is a Thursday
4946 MOD 7 can be calculated as 4 -(-1) + 9 - (2) + 4 - (3) + 1 - (6) MOD 7 = 32 MOD 7 = 4, but that also is
quite slow to calculate.
Date: 2022-04-09
Related videos
Comments and reviews: 9
Tim
For the year within the century part there's a way to calculate it that mostly does not involve any more than single digit arithmetic, which may be easier when dealing with years near the end of a century. Let the year be 10 T + Y. Forgetting about leap years for a moment, if T is even then the answer is 2 T + Y. If T is odd it is 2 T + Y + 3. For leap years, when T is even the leap years are Y = 4 or 8. When T is odd they are at Y = 2 or 6. Add 1 for each leap year in the decade. With this method you can stream the calculation as you read the date. For example for the first date in the video, June 18, 1976 as that is read I get 1 for June (-6 from the 6/6 mnemonic which I reduce mod 7 as I go, +4 for the day (18 mod 7, giving 5. +3 for the 19, giving 1. +3 for the 7 in 76 (2 x 7, +3 because 7 is odd, all reduced mod 7, bringing in the running total to 4. Then +6 for the 7 in 76, +2 for the leap years at 2 and 6, giving a final answer mod 7 of 5. The only place in this you have to deal with arithmetic on double digit numbers is when reducing the day of the month mod 7.
reply
For the year within the century part there's a way to calculate it that mostly does not involve any more than single digit arithmetic, which may be easier when dealing with years near the end of a century. Let the year be 10 T + Y. Forgetting about leap years for a moment, if T is even then the answer is 2 T + Y. If T is odd it is 2 T + Y + 3. For leap years, when T is even the leap years are Y = 4 or 8. When T is odd they are at Y = 2 or 6. Add 1 for each leap year in the decade. With this method you can stream the calculation as you read the date. For example for the first date in the video, June 18, 1976 as that is read I get 1 for June (-6 from the 6/6 mnemonic which I reduce mod 7 as I go, +4 for the day (18 mod 7, giving 5. +3 for the 19, giving 1. +3 for the 7 in 76 (2 x 7, +3 because 7 is odd, all reduced mod 7, bringing in the running total to 4. Then +6 for the 7 in 76, +2 for the leap years at 2 and 6, giving a final answer mod 7 of 5. The only place in this you have to deal with arithmetic on double digit numbers is when reducing the day of the month mod 7.
reply
Lauri
I just tried this for 10/7/1970, and it doesn't work, or I'm doing something wrong.
1972 is a 6, so 1970 is a 4, add the century, so 3+4 is a 7 (since 1900 is a Wednesday.
11/7 is a 7, so 10/7 must be a 6, right?
but the answer is wrong. The 10th of July 1970 is a Friday, not a Saturday.
Should I be taking away a leap year when doing subtraction?
Meaning that taking away 2 from 6, should I take away a leap year as well?
So it'd be 6-2-1 = 3.
Finishing the calculation by adding the century, doomsday is now a Saturday, so 10/7 would be a Friday.
Doing it like this, the method works, but there was no mention in the video about anything like this, so why doesn't the method shown work with this date.
reply
I just tried this for 10/7/1970, and it doesn't work, or I'm doing something wrong.
1972 is a 6, so 1970 is a 4, add the century, so 3+4 is a 7 (since 1900 is a Wednesday.
11/7 is a 7, so 10/7 must be a 6, right?
but the answer is wrong. The 10th of July 1970 is a Friday, not a Saturday.
Should I be taking away a leap year when doing subtraction?
Meaning that taking away 2 from 6, should I take away a leap year as well?
So it'd be 6-2-1 = 3.
Finishing the calculation by adding the century, doomsday is now a Saturday, so 10/7 would be a Friday.
Doing it like this, the method works, but there was no mention in the video about anything like this, so why doesn't the method shown work with this date.
reply
YoloMaxi
Can someone help me out? How do i think if we say i want to know the date for 9th feb 1952. So i calculate that doomsday 1952 is a 5 (friday. So 29th (because of leap year) of february is a 5 (friday) and i want to know what day 9th of feb 1952 falls on? I cant do the same that he does 0+12 because the nearest date i know is 29th feb and i cant do 5 - 20 (the difference between 9th and 29th) because that would be -15, and ultimately -1. And i cant do 5+20=25 ->4 (thursday) because its just wrong. TLDR: what do you do if the date you want to know the day of the week of is before the nearest doomsday date? Ex i want to know 9th feb and closest doomesday date is 29th feb.
reply
Can someone help me out? How do i think if we say i want to know the date for 9th feb 1952. So i calculate that doomsday 1952 is a 5 (friday. So 29th (because of leap year) of february is a 5 (friday) and i want to know what day 9th of feb 1952 falls on? I cant do the same that he does 0+12 because the nearest date i know is 29th feb and i cant do 5 - 20 (the difference between 9th and 29th) because that would be -15, and ultimately -1. And i cant do 5+20=25 ->4 (thursday) because its just wrong. TLDR: what do you do if the date you want to know the day of the week of is before the nearest doomsday date? Ex i want to know 9th feb and closest doomesday date is 29th feb.
reply
cole
How does leap years work with negative numbers when calculating the years of the century?
For example, 1947. It's closest to 56. It's -9 from 56. Negative numbers work with this algorithm and if your ultimate sum is a negative, you just add it to 7 to get the day. But how do I calculate the leap year going backwards like this from the closest restart pattern year? If I was going off of 28, 47-28=19=4 leap years =+2 year shifts. I can't figure out a way to work it from this angle of subtracting from a higher reset year, I'm not sure how to figure out what to plug in for the place of the leap year number without doing the same math using a lower reset year number.
reply
How does leap years work with negative numbers when calculating the years of the century?
For example, 1947. It's closest to 56. It's -9 from 56. Negative numbers work with this algorithm and if your ultimate sum is a negative, you just add it to 7 to get the day. But how do I calculate the leap year going backwards like this from the closest restart pattern year? If I was going off of 28, 47-28=19=4 leap years =+2 year shifts. I can't figure out a way to work it from this angle of subtracting from a higher reset year, I'm not sure how to figure out what to plug in for the place of the leap year number without doing the same math using a lower reset year number.
reply
Leshawn
Ever notice any month -blessed- enough to start on Sunday is also -cursed- with a Friday the 13th, eh? If the New Year starts on Thursday, there will be a February Fri/13, eh? Check Year of the form 28N +16. you get Leap/Feb/Fri/13, eh? (Last one was N=71. 2004, eh) I would ever so casually ask James G. to figure out the next one (N=72) right from the start. easy & clever, eh? Yet I'm always broke, huh? First comment ever online.
reply
Ever notice any month -blessed- enough to start on Sunday is also -cursed- with a Friday the 13th, eh? If the New Year starts on Thursday, there will be a February Fri/13, eh? Check Year of the form 28N +16. you get Leap/Feb/Fri/13, eh? (Last one was N=71. 2004, eh) I would ever so casually ask James G. to figure out the next one (N=72) right from the start. easy & clever, eh? Yet I'm always broke, huh? First comment ever online.
reply
Twenty69
Hello, I tried 2 techniques to find 2019 but I don't get the same result:
Example year 2019
2000 = Tuesday
Technique 1:
19 / 4 = 4
19 + 4 = 23
23 / 7 = 3 so (3 x 7 = 21)
23 - 21 = 2 (Thursday)
Technique 2:
Shortcut: 12 = 1
19 - 12 = 7
1 Leap year
2000 = Tuesday = 2
1 + 7 + 1 + 2 = 11
11 - 7 = 4 (Saturday)
Any ideas why?
reply
Hello, I tried 2 techniques to find 2019 but I don't get the same result:
Example year 2019
2000 = Tuesday
Technique 1:
19 / 4 = 4
19 + 4 = 23
23 / 7 = 3 so (3 x 7 = 21)
23 - 21 = 2 (Thursday)
Technique 2:
Shortcut: 12 = 1
19 - 12 = 7
1 Leap year
2000 = Tuesday = 2
1 + 7 + 1 + 2 = 11
11 - 7 = 4 (Saturday)
Any ideas why?
reply
Wulja
Hi, I have a question. When I take a date 7. 11. 1974 (my moms birthday, I knew at first that 7. 11 is a -special date- and it is 0. And when I do a year I get like, 3 (cz 1900 is Wednesday) + 6 (72) + 2 (to add to that 72 to get 74) + 1 leap year which sums up to 12, which is Friday and my moms born on Thursday. What am I doing wrong?
reply
Hi, I have a question. When I take a date 7. 11. 1974 (my moms birthday, I knew at first that 7. 11 is a -special date- and it is 0. And when I do a year I get like, 3 (cz 1900 is Wednesday) + 6 (72) + 2 (to add to that 72 to get 74) + 1 leap year which sums up to 12, which is Friday and my moms born on Thursday. What am I doing wrong?
reply
Davey2Wavey
The leap years are very confusing though, 2024 for example. Tue + 24 / 4. 24 + 5 = 29 - 28 = 1 ( Wednesday.
It should be Wednesday but because of leap years, it is actually Thursday. How do you know if the year is a leap year and should actually fall on the following year?
reply
The leap years are very confusing though, 2024 for example. Tue + 24 / 4. 24 + 5 = 29 - 28 = 1 ( Wednesday.
It should be Wednesday but because of leap years, it is actually Thursday. How do you know if the year is a leap year and should actually fall on the following year?
reply
Barry
That's a better method than the one I did a video explaining the method in 2012. I filmed that so many times to get under the five minute time limit LOL but it sure beats memorizing a different number based on the month. I found the method I explained in a math fun book.
reply
That's a better method than the one I did a video explaining the method in 2012. I filmed that so many times to get under the five minute time limit LOL but it sure beats memorizing a different number based on the month. I found the method I explained in a math fun book.
reply
Add a review, comment
Other channel videos















