Originally Posted by
Neo1
I'm trying to implement this algorithm into a program
First of all you seem to be trying to do the calculations using a formula that assumes that the Gregorian calendar has been in effect since the year zero. Beside the fact that your assignment of weekdays corresponding to 0, 1, 2, 3 gives the wrong answers, there are two other fundamental errors:
1. There was no year zero.
2. The Gregorian Reformation occurred on September 3, 1752, at which time ten days were "sklpped". This is mentioned on the web site that you linked us to.
Note that the "real" February, 1700, which was on the Julian calendar, looks like the following, and "Doomsday" for 1700 is not correctly calculated from the algorithm on the site that you referenced.
Code:
February 1700
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29
Date calculations before September 14, 1752, should take the "missing" 10 days into account.
It is important to know the difference if you use other places as a reference to check the answers that you finally end up with. And, of course, you have to check your answers, somehow, against some other reference, right? (Never get all of your information from one source, I say.)
Forgetting that for a moment, look at the days for the "Doomsday" in the century years starting with 1800:
1800: Friday
1900: Wednesday
2000: Tuesday
2100: Sunday
2200: Friday
2300: Wednesday
2400: Tuesday
2500: Sunday
I guess you could extend this backwards to the year zero if you wanted, but the actual dates would not be correct on "real" calendars for century years before 1800.
Anyhow, if you wanted to make some kind of mathematical relation between the century and the day of the week, you could write the following, just using the century = (year / 100)
18: Friday
19: Wednesday
20: Tuesday
21: Sunday
22: Friday
23: Wednesday
24: Tuesday
25: Sunday
Since there is a periodicity of four, we notice that a division of the century modulo 4 gives all the information that is needed:
18%4 = 2 ---Friday
19%4 = 3 ---Wednesday
20%4 = 0 ---Tuesday
21%4 = 1 ---Sunday
22%4 = 2 ---Friday
23%4 = 3 ---Wednesday
24%4 = 0 ---Tuedsay
25%4 = 1 ---Sunday
Putting these together, you could create a program based on the following:
Instead of using a loop to count the number of centuries from the non-existent year zero (which would have had a doomsday of Tuesday if there were a year zero and if the Gregorian calendar had been in effect at that time), Just take the century modulo 4 and use the following relationship:
(century % 4) == 0 Implies that doomsday for year 00 of that century is Tuesday
(century % 4) == 1 implies that doomsday for year 00 of that century is Sunday
(century % 4) == 2 implies that doomsday for year 00 of that century is Friday
(century % 4) == 3 implies that doomsday for year 00 of that centuryr is Wednesday
D