The Computation of the day of
the week (Mark Dettinger )
Altre 2 tecniche per il calcolo dei giorni della settimana (v. L.Carroll) |
Most
people need a calendar to determine the day of the week of a given date.
But why? It's so easy to compute it in your mind: How it works Let c be the century, y the year (0<=y<=99), m the month and d the day. Compute the code numbers C,Y,M and D. Compute x = C+Y+M+D mod 7. Then the day of the week is given by |
|||||||||||||||||||||||||||
|
The Century Code
Every
400 years the days of the week repeat. July 5, 1995 was a Wednesday,
so July 5, 2395 will be a Wednesday again, for example. |
||||||||||||||||||||||||||
The Year CodeY = (y div 12) + (y mod 12) + ((y mod 12) div 4)Example: The year 1995 Y = (95 div 12) + (95 mod 12) + ((95 mod 12) div 4) = 7 + 11 + 2 = 20 = 6 (mod 7) The following equivalent formula was suggested by Mike Keith. It involves fewer operations, but with higher numbers. Y
= y + (y div 4) Both
formulae can be generalized to the following method: The first formula uses the highest possible q, the second one immediately sets q=0 and r=y. As
q can be chosen arbitrarily in the range [0..(y div 12)], a good choice
depending on y may lead to an even easier mental computation. To
further simplify the computation, you can compute y' = y mod 28 first
and then use y' instead of y in the formula. 95 mod 28 = 11, so for
1995 the calculation would be: OK, the computation is still nasty. Therefore Vidar Sveen (another member of the 1000-Club) suggested to me that it were probably better to memorize all year codes from 00 to 99. The Month Code
The
numbers in brackets go for leap years. |
|||||||||||||||||||||||||||
The Day CodeD = dExample: November 27, 199520th century => C=0 Year 95 => Y=6 Month November => M=4 Day 27 => D=27 C+Y+M+D = 0+6+4+27 = 37 = 2 (mod 7) = Monday |
|||||||||||||||||||||||||||
Another
Technique The following method was suggested by Chris McManus. He also is an expert for Graeco-Latin Squares and their variants. Whatever day of the week (DOW) March 0 (Last day of February) falls on, so do 4-4 (April 4), 6-6 (June 6), 8-8 (August 8), 10-10 (October 10), and 12-12 (December 12). Also falling on the same DOW are 9-5 (May 9), 7-11 (November 7), and their inverses 5-9 (September 5) and 11-7 (July 11). Memory aid: "I hate my 9-to-5 job at the 7-11 Store." So, if today is Wednesday, October 9, 1996, and you want to figure out what day was April 13, 1996, you just have to calculate what 10-10 will be (tomorrow -> Thursday). Then 4-4 was also a Thursday, so 13-4 is 9 days later, a Saturday. |