Question: QUESTIONS 3: Computing the Day of the Week [40] When calculating the day of the week for any given day in Gregorian calendar, several methods

 QUESTIONS 3: Computing the Day of the Week [40] When calculating

the day of the week for any given day in Gregorian calendar,

QUESTIONS 3: Computing the Day of the Week [40] When calculating the day of the week for any given day in Gregorian calendar, several methods exists. The most common approach makes use of Doomsday rule, an algorithm devised by a mathematician named John Conway in 1973 Doomsday algorithm "takes advantage of each year having a certain day of the week (the doomsday) upon which certain easy-to-remember dates such as 4/4, 6/6, 8/8, 10/10, 12/12, etc., all occurring on the same day of the week in any given year". In other words, if the doomsday for year 2017 is Tuesday, then days such as 4 April, 6 June, 8 August, etc., will all fall on Tuesday Further, the algorithm involves treating days of the week like numbers as shown in Table 1 Table 1: Index of Day of Week Day of Week Assigned Number 0 Sunda Monday Tuesday Wednesda Thursday Saturda Computing day of the week for any given day involves several steps STEP 1 Finding the doomsDay for a given year For this problem, we will employ the "odd + 11" technique as follow: 1. Let T be the given year's last two digits 2. If T is odd, then T1 T + 11, otherwise T1 = T 3. Let T2 4. If T2 is odd, then T3 T211, otherwise T3T2 5. Let T47- (T3 mod 7) 6. doomsDayanchorDay T4 7. If doomsDay in step 6 is a number greater than or equal to 7, then subtract 7 to get the T1 correct doomsDay A table listing several centuries' anchor days is shown below: Table 2: Centuries Anchor day Centuries 1700 1799 1800 1899 1900 1999 2000 2099 2100 2199 Anchor day Sunday Friday Wednesday Tuesday Sunda STEP 2 Finding the Day of the week (dayOfWeek) for a given date (dd/mm/yyyy) 1. From the table below (Table 3), find the closest doomsday (closerDDay) to the given day (of the same month). Example, if the given day is 25 December 2006 (25/12), then the closest doomsday is 12 December 2006 (12/12) Compute Day of Week as follows 2. dayofWeek (doomsDay+(givenDay closerDDay)) mod 7 If the result in step 2 is a negative number, add 7 to your result. Otherwise if your result is a number greater than or equal to 7, then subtract 7 to get the correct dayofWeek 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!