Algorithm wanted

Roy J. Mongiovi roy at gitpyr.UUCP
Sun Dec 9 05:53:05 AEST 1984


> Make sure that whatever algorithm you get takes the following
> into account about leap years:
> 
> a) Any year divisible by 4 is a leap year, unless
> b) it is divisible by 100 as well, in which case it is NOT a leap
>    year, unless
> c) it is divisible by 400 as well, in which case it is a leap year
>    after all.
> 
> What stupid rules!

What do you mean "what stupid rules!" ?  It happens to be an approximation
of the ratio of the time it takes the earth to rotate around the sun to
the time it takes it to rotate on its axis.  Perhaps we should change one or
the other of those numbers to make the approximation more esthetic?  :-)

Also, you can carry the approximation one place further (if for any reason
you would need to) by taking into account that if the year is divisible by
4000, then it isn't a leap year after all.

On a slightly different track, you can determine the number of days preceeding
the beginning of a particular month by looking it up in a table, or by using
an interesting method known as Zeller's Congruence.  If you consider a year to
start on March 1 and continue through February 28 (or 29), it forms a pattern
which can be approximated to enough accuracy to ensure accurate results (all
the error is in the fraction).  The number of days preceeding the beginning of
month N is (153 * N + 2) / 5 when computed with integer operations.  The table
is probably the better idea, but Zeller's Congruence rather appeals to me
somehow....
-- 
Roy J. Mongiovi.	Office of Computing Services.		User Services.
Georgia Institute of Technology.	Atlanta GA  30332.	(404) 894-6163
 ...!{akgua, allegra, amd, hplabs, ihnp4, masscomp, ut-ngp}!gatech!gitpyr!roy

	  Who me?  I'm not even a REAL modo, I'm only a quasi-modo.



More information about the Comp.sources.unix mailing list