Doomsday rule: calculate the day for any date
en.wikipedia.org
en.wikipedia.org
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.
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.
It saddens me.
I'd sit with someone who did this and learn how it works!
My party trick clears the room: eye socket farts.
(CC=century digits F=First S=Second digit of the last two digits in year)
Note:Only for Gregorian calendar.Formula= {D +Table(M) -1 IF month=1or2&leap_year +Table(CCmod4) +Table(F) +Table(S +2 IF F is odd) } mod7
Tables are:
Month {033614625035} or Jan=0 Feb=3 Mar=3 Apr=6 etc.
Century {6420} or 16xx=6 17xx=4 18xx=2 19xx=0 20xx=6 etc.
TableFirst memorize {0340145025} or {00,13,24,30,41,54,65,71,82,95}
TableSecond memorize {012356013456} or {00,11,22,33,45,56,60,71,83,94,105,116}
FormulaResultTable:1=Monday...6=Saturday 0=Sunday
Example: 16 August 2014 = (16+2+6+3+0)mod7=6=SaturdayIn this method,I find slight advantage over "odd+11 method" because my method does not involve two digit arithmetric (and memorizing running total if you're not calculating FS first),although learning tables take some time.
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/Edit: no idea how to work spacing on comments here
> 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. calculateDay = (year, month, day) ->
y = (year - 2000) % 28
m = [6,2,2,5,0,3,5,1,4,6,2,4][month]
m-- if month < 2 and y % 4 is 0
y += (y / 4) | 0
['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][(y + m + day) % 7]Turns out that sakamoto's algorithm (see https://en.wikipedia.org/wiki/Calculating_the_day_of_the_wee... ) was much faster to calculate and made for cleaner code. https://github.com/daurnimator/luatz/blob/master/luatz/timet...
Created an issue at https://github.com/daurnimator/luatz/issues/2
You know, "Conway's Game of Life", "Doomsday rule"... He's not into small names for the things he invented.
As for your question why, I cannot reasonably guess. :-)
Somewhat related, you may be interested to read up about the Doomsday Book.
"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."
sunrise: not reached :|
The core idea is that August 10th is a semi-meaningless count of the days, whereas the real information lies in today being Sunday.