Hacker News new | ask | show | jobs
by stoltzmann 845 days 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.

1 comments

Fortunately, it's not a very big N. ;)