5 ms·
Great start. Now let's add leap years. =)
by joezydeco 12y ago
Great start. Now let's add leap years. =)
- _lce0 12y agobut that's trival, isn't that already solved? function f(x) { return 28 + maybeLeap(x) + (...); } I remember it's something related with "(x % 4) == 0" and "not ends_with(00)"
- agrona 12y agoExcept for every 400th year.
- _lce0 12y agohow about this? leap = function(x) { if ((x % 4) != 0) { return 0; } return Number( (x % 100) != 0 || (x % 400) == 0 ); } function(x) { return 28 + leap(x) + (...) };
- joezydeco 12y agoOP is trying to express the day count as a pure math expression. maybeLeap() probably won't do here.
- sparkie 12y agodays y m = 28 + (m + (m `div` 8)) `mod` 2 + 2 `mod` m + 2 * (1 `div` m) + ((2 `div` m) `mod` 2) * (leap y) where leap y = multiple 4 y - multiple 100 y + multiple 400 y where multiple int y = ((y + (int - 1)) `mod` int + 1) `div` int