A Leap Year Check in Three Instructions

2025-05-15

This article presents a surprisingly efficient algorithm to determine if a year (0 ≤ y ≤ 102499) is a leap year using only about three CPU instructions. It leverages bit manipulation and carefully chosen magic numbers to transform the complex leap year rules into a simple arithmetic operation and comparison. The author meticulously explains the algorithm's derivation, comparing it to traditional methods and highlighting its significant speed advantage. While slightly slower in edge cases, its efficiency in practical applications is impressive.

Read more
Development leap year