4 ms·
Here's the easiest way I’ve seen [1] to determine if a year is a leap year: If the last two digits of the year are 00, throw them away and keep only the first
by bumbledraven 7y ago
Here's the easiest way I’ve seen [1] to determine if a year is a leap year:
If the last two digits of the year are 00, throw them away and keep only the first two digits. Otherwise, keep only the last two digits. The year is a leap year if what you kept is divisible by 4.
Examples:
- The year 1705 does not end in 00, so throw away 17 and keep 05. 05
is not divisible by 4, so 1705 is not a leap year.
- The year 2000 ends in 00, so throw away 00 and keep 20. 20 is
divisible by 4, so 2000 is a leap year.
The standard method [2] is more complicated:
> Years that are divisible by four are leap years, with the exception of years that are divisible by 100, which are not leap years, and with the final exception of years divisible by 400, which are.
[1] https://twitter.com/jordancurve/status/1012203999716618240 https://twitter.com/jordancurve/status/1012203999716618240
[2] https://www.theguardian.com/science/2011/feb/28/leap-year-alex-bellos https://www.theguardian.com/science/2011/feb/28/leap-year-al...
- rovr138 7y agoGot tricked during a CS course with this. I bet a lot of the people in that class will remember the full rule. It then came back on the final.
- bumbledraven 7y agoWhat do you mean, “tricked”? The method is original to me and I don’t think it has spread very far. Is there a Gregorian calendar year for which the GP algorithm gives the wrong result?
- htfu 7y agoThe two methods are exactly - exactly - the same. Just different ways of phrasing. Don't fool yourself.
- bumbledraven 7y agoThe standard method and mine give the same result, and I believe that mine is simpler to carry out in your head. In what way do you believe that I am fooling myself?
- stinos 7y agoNot so much as fooling yourself, but I agree with the OP your method isnt really 'original' in the sense that it's indeed exactly the same as the 'standard' one, just a tad different in how you explain the math. E.g. 'if not ending in 00 throw away...' is really just the same thing as 'except when divisable by 100'.
- jolmg 7y agoTo add to your comment, being divisable by 400 is also the same thing as throwing away the 00 and checking the remaining is divisable by 4. One explanation is just a rephrasing of the other for the exact same method.
- firethief 7y agoIt's algebraically equivalent, but it's not the same procedure. The insight in Bumbledraven's Algorithm is that by factoring out an unconditionally-performed mod-4 step, the problem can be reduced to two cases.