4 ms·
An amusing way to keep your mental math skills working is to compute the day of the week for calendar dates. (There's a few ways to do this that are published
by pklausler 10y ago
An amusing way to keep your mental math skills working is to compute the day of the week for calendar dates. (There's a few ways to do this that are published on the Web, e.g. the "Doomsday" method, but one can derive much faster methods with a little analysis.)
You can quickly gain a kind of "Rain Man" reputation if somebody mentions a date and you instantly mutter "Saturday". But it's just a matter of adding three numbers and taking the remainder modulo 7.
- oh_sigh 10y agoCan you provide a link to a method that is faster than the doomsday algorithm? If I know the doomsday for a given year, I can get the day of week for a date in about 3 seconds. I'd love to get that even faster(or have a faster method when I don't know the doomsday)
- pklausler 10y agoMemorize this table of offsets: 0 Oct, Jan 1 May 2 Aug 3 Feb, Mar, Nov 4 Jun 5 Sep, Dec 6 Apr, Jul Precalculate the offset for the year (2017 is 117 + trunc(117/4) == 146 == 6 mod 7). Then the day of the week for, say, today, is 6 (for the year) + 3 (for Feb) + 23 (day of the month) == 32 == 4 mod 7, which is Thursday . Other examples: D-Day, 6 June 1944, was (44+11 == 55 == 6 mod 7 for the year) + 4 (Jun) + 6 == 16 == 2 mod 7 == Tuesday. The only twist is needing to subtract 1 from the result for dates in Jan and Feb on leap years, since those dates precede the leap day.
- pmoriarty 10y agoI don't understand how you got the "6 mod 7" in the two examples above. Everything else makes sense, though. Thanks.
- dahart 10y agoTaking a number of any size mod 7 can also be done in your head, from left to right! First time I saw this was in intro to theoretical CS, where the exercise is create a state machine for mod 7. It was a big surprise for me that it's super simple and you just feed it digits til you run out. Almost trivial to do mentally on very large numbers as fast as someone can speak the number, with just a little practice.