Sunday, May 11, 2008

Zeller's Formula

I was a puzzle breaker in my college days. It is all becuase I had an excellent group of pals interested in puzzle solving.

When we were preparing for MCA entrance examinations and later for campus interviews we used to work out problems from R.S. Agarwal's "Objective & Arithmetic". I really like this book though it contains simplest problems in the world only because the solution sections are more descriptive and very easy to understand.

One of the interesting topics in this book is that finding day of the week of a given date. Again R.S.A's book provides you the method to solve problems of this kind. I used to go with this method until I come across Zeller's formula. The Zeller's formula to find day of the week of any given date is an one step formula,

f = D + [(13M-1)/5] + [5Y/4] + [C/4] - 2C

Where D is the day of the month. Let's use January 29, 2064 as an example. For this date, D = 29.

M is the month number. Months have to be counted specially for Zeller's Rule: March is 1, April is 2, and so on to February, which is 12. (This makes the formula simpler, because on leap years February 29 is counted as the last day of the year.) Because of this rule, January and February are always counted as the 11th and 12th months of the previous year. In our example, M = 11.

Y is the last two digits of the year. Because in our example we are using January (see previous statement) Y = 63 even though we are using a date from 2064.

C stands for century: it's the first two digits of the year. In our case, C = 20.

And the symbol [ ] denotes the integer part of the given number. The integer part of number x, [x], is the greatest integer not exceeding x. For instance,

[3.99] is 3 and [3.001] is also 3.

Now let's substitute our example numbers into the formula.

f = k + [(13*m-1)/5] + D + [D/4] + [C/4] - 2*C

= 29 + [(13*11-1)/5] + 63 + [63/4] + [20/4] - 2*20

= 29 + [28.4] + 63 + [15.75] + [5] - 40

= 29 + 28 + 63 + 15 + 5 - 40

= 100.

Once we have found f, we divide it by 7 and take the remainder.

A remainder of 0 corresponds to Sunday, 1 means Monday, etc. For our example, 100 / 7 = 14, remainder 2, so January 29, 2064 will be a Tuesday.

No comments: