A simple formula to calculate what day (Mon-Sun) any given date is/was/will be
Karl Friedrich Gauss, one of the greatest mathematical physicists ever, and also known as the prince of mathematics (quite aptly so), had originally developed a formula using nothing other than simple arithmetic, to calculate the weekday of the 1st of January of any possible year. Even better, his formula can be used for both the Gregorian and Julian calendars, but since we're using Gregorian one anyway, let's stick to that.
The formula, published after the death of Gauss, can be modified easily to calculate the weekday of any given date, which is pretty straightforward and neat.
The formula
Without further ado, here it is:
W = { D + ( 2.6M - 0.2 ) + 5 Rem ( Y , 4 ) + 4 Rem ( Y , 100 ) + 6 Rem ( Y , 400 ) } mod 7
So, it requires a bit explanation at first.
1. W = the weekday constant, which is to be matched against a rather simple table, here it is:
W = 0 -> Sunday
W = 1 -> Monday
...
W = 6 -> Saturday
2. D = the date of the month, aka 22 for today, 23 for tomorrow etc.
3. M = f(m), a function of the month's number, given as M = f(m) = ( m - 2 ) mod 12, i.e subtract 2 from the month's number (1-12), divide it by 12 and grab the remainder. Also, it's 12 for February, and not 0.
Still, for simplicity, here's the list:
M (January) = -1
M (February) = 12
M (March) = 1
...
M (December) = 10
4. Y = the year. Y = 2014 for this year.
5. Rem is a remainder function, i.e Rem ( a , b) = remainder when b divides a.
Example for today
Unlike other sciences that require experimental verification, the beauty of math is that, you only need pen, paper and some brainpower. That's why, let's calculate the weekday for today, and see if the formula works.
So, for today, the year is 2014, date is 22nd and the month is September, i.e the 9th month. Naturally,
W = { 22 + ( 2.6 * 7 - 0.2 ) + 5 Rem ( 2014 , 4 ) + 4 Rem (2014 , 100 ) + 6 Rem (2014 , 400 ) } mod 7
= { 22 + 18 + 5 x 2 + 4 x 14 + 6 x 14 } mod 7
= 190 mod 7
= 1 (since 190 = 7 x 27 + 1 , evidently).
Now, W = 1 -> Day = Monday!
Further simplification and a second example
One problem with this formula is that, calculations get lengthy at times. For example, if you intend to calculate the weekday of India's independence (August 15, 1947), then calculations using this formula will get long, and error-prone. Naturally, it can be simplified further with a simple modification:
Y = y + 100C,
where y = last two digits of the year (i.e YEAR mod 100), and C = the current century, i.e 20 for this one.
Then, W = { D + ( 2.6 x M - 0.2 ) + 5 Rem ( y , 4 ) + 3 Rem ( y , 7 ) + 5 Rem ( C , 4 ) } mod 7
Let's verify the weekday of India's independence, 15th August, 1947. We know that it was a Friday, and let's check it.
So, W = { 15 + ( 2.6 x 6 - 0.2 ) + 5 Rem ( 47 , 4 ) + 3 Rem ( 47 , 7 ) + 5 Rem ( 19 , 4 ) }
= { 15 + 15.4 + 5 x 3 + 3 x 5 + 5 x 3 } mod 7
= 75.4 mod 7
= 75 mod 7 (75.4 rounded off)
= 5,
And naturally, W = 5 -> Day = Friday.
Conclusion
There are other methods for the same purpose. I posted one last year, which can be found here: http://goo.gl/dUPXZV (same guy here, just posting as my page this time)
Also, there's Kraitchik's algorithm, but Gauss's method is better than both because it doesn't need us to remember any table of constants. This is why this simple algorithm continues to be my favourite.
FacebookAutoShare
#mathematics #mathtricks #science #calendar
from Stuff That Matters! - Google+ Posts http://ift.tt/1mCemFv
via IFTTT
No comments:
Post a Comment