leap year problem (w/o using loops)
Date: 06/27/05
(Algorithms) Keywords: no keywords
So I am writing a program that will calculate the number of days since 1/1/1600 till the date passed to the function.
I used this calculator to check my test cases so that I don't have to do them all by hand.
However of the ~50 cases I put in all work, except for 09/01/6912. My code gives me 1940413. I get that by hand too. (365*5312 + 13*97 [97 leap years in block of 400)+ 25 [25 in the first hundred years of the block of 400] + 3 [3 blocks of 4] + 243 [number of days from jan-aug, counting feb as 28] + 1 + 1 [adding th e leap day since it is after febuary on a leap year] - 1 [don't count in the end points]) The calculator gives 1940412. Arrrrr.
Am I just being dumb, and calculating it wrong by hand too? or is that calculator messing up?
(leap years being years divisble by 4, unless they are divisible by 100, in which case they have to be divisible by 400.)
Edit: caught it. Fixed it. Thanks. =)
Source: http://www.livejournal.com/community/algorithms/57925.html