
Doomsday rule: calculate the day for any date - iamwil
https://en.wikipedia.org/wiki/Doomsday_rule
======
gamegoblin
Freshman year of uni I memorized some variant of this, and after some practice
I got to where I could do the math in 3-5 seconds.

Protip: Some parts of the algorithm can be subject to a CPU/Memory trade off.
In the variant presented in the wiki article, steps 1 and 2 can be combined.
Memorize the doomsdays for all of the years of people you're likely to want to
calculate their date of birth. For me, this meant memorizing the doomsdays
between say, 1980 and 1995.

You can also memorize a modulo 7 table for all numbers you're likely to
encounter.

You can get fast enough in the amount of time it takes you to say some canned
response "Hmm, I think the date X YYth of ZZZZ would fall on..." you can
figure out the answer.

\-----

Though it turns out this is a significantly less impressive party trick as I
initially imagined it'd be.

~~~
iamwil
People aren't impressed by it?

~~~
gamegoblin
Only a certain kind of people really appreciate it.

Generally, the same kind of people who are impressed by rubik's cube
speedsolving (which I _also_ thought would be amazingly cool) are impressed by
this. But for a lot of people, they just assume there is some simple trick to
it, say "cool" and move on.

And then other people assume you must be some sort of autistic savant.

~~~
dools
I found the same for the ability to divide numbers by 17 in my head... it
really didn't get me a lot of action.

------
hashmymustache
Not sure how the doomsday works, but there's a quick way to calculate the day
of week just memorizing single digit codes for months. Might be easier to grok
from a small script. This is for current century (2000s) in coffeescript:

calculateDay = (year,month,day) ->

    
    
      y = (year-2000)%28
      m = [6,2,2,5,0,3,5,1,4,6,2,4][month]
      if month < 2 and y%4==0
          m-= 1
      y += y/4|0
      days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
      return days[(y+m+day)%7]
    

\--- For years 1600s through current century here's a jsfiddle with a slightly
longer method with verification:
[http://jsfiddle.net/9zp0zkxz/](http://jsfiddle.net/9zp0zkxz/)

Edit: no idea how to work spacing on comments here

~~~
ColinWright

      > no idea how to work spacing on comments here
    

* Blank lines create new paragraphs,
    
    
      Blank line followed by lines with
      leading spaces create pre-formatted
      text - intended for inserting code.
    

Under most circumstances, asterisks around text creates _italics,_ the
exception is when the asterisk is surrounded by space.

\--
[https://news.ycombinator.com/formatdoc](https://news.ycombinator.com/formatdoc)

~~~
hashmymustache
ah, thank you

------
adamnemecek
The 'Big Calendar' industry is going down.

~~~
madcaptenor
Big Calendar is already on its way down. How many of us even have calendars?

------
daurnimator
When I wrote my time and date library (luatz:
[https://github.com/daurnimator/luatz](https://github.com/daurnimator/luatz) )
I originally wrote an implementation of the Doomsday rule to figure out the
day of the week.

Turns out that sakamoto's algorithm (see
[https://en.wikipedia.org/wiki/Calculating_the_day_of_the_wee...](https://en.wikipedia.org/wiki/Calculating_the_day_of_the_week#Implementation-
dependent_methods_of_Sakamoto.2C_Lachman.2C_Keith_and_Craver) ) was much
faster to calculate and made for cleaner code.
[https://github.com/daurnimator/luatz/blob/master/luatz/timet...](https://github.com/daurnimator/luatz/blob/master/luatz/timetable.lua#L45)

~~~
apaprocki
IIRC tzdata just acquired a new version (3) not too long ago and luatz would
need to be updated to handle it. You'll only get the new files if they were
compiled with a newish zic. This bit me because code I work with is also
parsing them :)

~~~
daurnimator
Thanks for mentioning this, I had no idea... and documentation on this fact is
sparse. It's not even mentioned on [https://www.iana.org/time-
zones/repository/tz-link.html](https://www.iana.org/time-zones/repository/tz-
link.html)

Created an issue at
[https://github.com/daurnimator/luatz/issues/2](https://github.com/daurnimator/luatz/issues/2)

------
cstuder
Why are those days called 'doomsdays'? Anybody knows? (The origin articles
don't seem to be online.)

~~~
scotty79
Maybe because its inventor is John Conway?

You know, "Conway's Game of Life", "Doomsday rule"... He's not into small
names for the things he invented.

------
apeconmyth
As I explained to a friend recently, I'm not the type of person who can
readily do the calc in my head, but rather the type who would enjoy the
tedious work of laying out all the possibilities on paper, as I did with the
Periodic Calendar:
[http://periodiccalendar.com/](http://periodiccalendar.com/)

------
troymc
"Pick a date, any date."

"June 12, 2145."

"A Saturday. In Vancouver, sunrise will be at 5:12am and sunset will be at
9:24pm. There will be a third quarter moon."

"Wow."

[http://www.wolframalpha.com/input/?i=June+12%2C+2145](http://www.wolframalpha.com/input/?i=June+12%2C+2145)

~~~
rdvrk
[http://www.wolframalpha.com/input/?i=January+2%2C+218129](http://www.wolframalpha.com/input/?i=January+2%2C+218129)

sunrise: not reached :|

------
bumbledraven
The First Sunday Doomsday Algorithm is the easiest to learn and also fastest,
in my opinion.
[http://firstsundaydoomsday.blogspot.com/](http://firstsundaydoomsday.blogspot.com/)

------
jozydapozy
This script will test your skills on logon:
[https://code.google.com/p/doomsday-sh/](https://code.google.com/p/doomsday-
sh/)

------
jeffboudier
The periodic calendar provides a map to this math:
[http://periodiccalendar.com/learn/](http://periodiccalendar.com/learn/)

~~~
apeconmyth
Thanks, Jeff! The key to the Periodic Calendar is identifying that there are
seven types of years, depending on the day of the week that starts it off. At
first I thought I needed to make 7 calendars to cover the possibilities, but
my aha moment came with the idea of the Gregorian Isotopes, which flip our
focus from the day of the month to elements based in days of the week that
exist on an array of days of the month.

The core idea is that August 10th is a semi-meaningless count of the days,
whereas the real information lies in today being Sunday.

------
oh_sigh
This rule is great for convincing people that you are autistic.

