Path: utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!uw-june!uw-entropy!dataio!suvax1!hirayama From: hirayama@suvax1.UUCP (Pat Hirayama) Newsgroups: comp.sys.ibm.pc Subject: Re: day of week Message-ID: <961@suvax1.UUCP> Date: 3 Feb 88 16:46:35 GMT References: <141900013@occrsh.ATT.COM> Organization: Seattle University, Seattle, WA. Lines: 64 In article <141900013@occrsh.ATT.COM>, fubar@squid.UUCP writes: > *** > *** PLEASE send replies to ihnp4!occrsh!squid!david > > > Here's a formula given in the book An Introduction to the Theory of Numbers, > >by Niven and Zuckerman. > > Let M be the number of the month, defined so that Jan = 11, Feb = 12, > >Mar = 1, Apr = 2, ..., Dec = 10. Let N be the number of the day within the > >month. Let C be the hundreds in the year, and let Y be the rest of the year. > >Let L be 1 for a leap year and 0 for a non-leap year. > > > > > >(N + [2.6M - 0.2] + Y + [Y / 4] + [C / 4] - 2C - (1 + L)[M / 11]) mod 7 > >yields 0 for Sunday, 1 for Monday, ..., 6 for Saturday. > > > >(Square brackets denote the greatest integer function.) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Thursday, Jan 28, 1988, should yield 4: > > N = 28 (number of day within month) > M = 11 (Jan = 11) > C = 19 (Hundreds w/in year) > Y = 88 (rest of year??) > L = 1 (1988 is leap year) > > = (N + [2.6M - 0.2] + Y + [Y/4] + [C/4] - 2C - (1+L)[M/11]) mod 7 > = (28 + (2.6*11)-0.2] + 88 + [88/4] + [19/4] - (2*19) - (1+1)*[11/11]) mod 7 > = (28 + [28.4] + 88 + [22] + [4.75] - 38 - 2) mod 7 > = (28 + 29 + 88 + 22 + 5 - 38 - 2) mod 7 > = 6 ?? > > What is the correct formula for this? David, You are ignoring the underlined statement indicated above. If you consider this, you will realize the following: Given, your initial data values given above. Let X=Number you are seeking... X = (N + [2.6M - 0.2] + Y + [Y/4] + [C/4] - 2C - (1+L)[M/11]) mod 7 = (28 + (2.6*11)-0.2] + 88 + [88/4] + [19/4] - (2*19) - (1+1)*[11/11]) mod 7 = (28 + [28.4] + 88 + [22] + [4.75] - 38 - 2) mod 7 = (28 + 28 + 88 + 22 + 4 - 38 - 2) mod 7 = 4 Which is Thursday and the answer that you expect to get. ------------------------------------------------------------------------------ Pat Hirayama UUCP: ...!uw-entropy!dataio!suvax1!hirayama Seattle University USNail: 28625-47th Pl S, Auburn, WA 98001-1140 Class of 1988 Phone: (206) 946-0833 ". . . the starships of the Federation are the physical, tangible manifestations of humanity's stubborn insistence that life does indeed mean something." Spock Final Frontier ------------------------------------------------------------------------------