Re: Year 2000 is NOT a leap year
Posted in 1997
>From: newsrdr@mew.corp.sgi.com (Pablo Sanchez) >Date: 9 Jul 1997 18:53:27 GMT >X-Informix-List-Id: <news.40266> > >In article <5q0jgu$125$1@wetware.wetware.com>, cse@news.wetware.com writes: >> Gee, I didn't read into John's comment any sort of *tone*. >Perception. >[...] Please will both of you stop arguing (in public, at any rate). Thank you defending me Scott. Pablo, my previous articles on this subject both used language which could easily be interpreted as inflammatory, and for that I apologise. The original message which sparked the whole debacle off also used somewhat inflammatory language, and the undergrowth was dry enough for the whole brush fire to get out of control. -- FWIW, the example program I posted yesterday has a glaring error in it. The 'return(1)' should only be executed when the 'if' statement evaluates to true, so there should be braces around the printf() and the return. Fixing the bug doesn't alter my conclusion -- there is no difference between the results returned by my algorithm and the results returned by Pablo's algorithm. Nor does it alter the fact that Pablo's formula is significantly more efficient than mine because it weeds out the simple case (where the year is not divisible by 4) more rapidly than mine does. In fact, a measurement suggests that it is about 37% more efficient on average (much more than the hypothesized 0.14% :-) ). %Time Seconds Cumsecs #Calls msec/call Name 37.2 7.21 7.21 8247000 0.0009 johnl 27.1 5.26 12.47 8247000 0.0006 pablo 19.8 3.83 16.30 _mcount 15.9 3.09 19.39 1 3090. main I timed 1000 iterations of the (corrected) main loop in a test to produce the results above on a Sun Sparc 20 running Solaris 2.5.1. The rounding in the msec/call exaggerates the performance difference. A calculation with more significant digits shows that my code takes 0.874 microseconds per call and Pablo's takes 0.637 usec/call. In a production program, I'd never use the algorithm I used to explain the formula for leap years because it is not efficient as Pablo's formula. But my algorithm does explain how to determine whether a year is a leap year without any but's or unless's and is useful for its intended pedagogical purpose -- to explain succinctly why the year 2000 is a leap year. Everybody should treat this matter as closed from here on. Don't forget that it may take a couple of days for this closure to percolate around the world, but there should be no need for anyone to respond publicly after this. Yours pacifically, Jonathan Leffler (johnl@informix.com) #include <flamequencher.h> PS: I decline to respond to messages with anti-spam in the return path. -- Corrected version of the test program with the timing loop in place. -- The program produces no output (pure Unix style!) #include <stdio.h> typedef enum { false, true } Boolean; Boolean pablo(int year) { Boolean leap_year; if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) leap_year = true; else leap_year = false; return(leap_year); } Boolean johnl(int year) { Boolean leap_year; if (year % 400 == 0) leap_year = true; else if (year % 100 == 0) leap_year = false; else if (year % 4 == 0) leap_year = true; else leap_year = false; return(leap_year); } int main() { int loop; int year; for (loop = 0; loop < 1000; loop++) { for (year = 1753; year <= 9999; year++) { if (pablo(year) != johnl(year)) { printf("Year %d, Pablo %d, JohnL %d\\n", year, pablo(year), johnl(year)); return(1); } } } return(0); }