3 ms·
Pedantic but this drives me nuts - this algorithm has to do 3 divisions for almost every year. If you flip it upside down, it's significantly faster. * Is the
by stoltzmann 3y ago
Pedantic but this drives me nuts - this algorithm has to do 3 divisions for almost every year. If you flip it upside down, it's significantly faster.
* Is the year divisible by 4? NO -> not leap year
* YES -> Is the year divisible by 100? NO -> leap year
* YES -> Is the year divisible by 400? NO -> not leap year
* YES -> leap year
This way you do only 1 division for 75% of years.
- daveguy 3y agoFortunately, it's not a very big N. ;)