Re:A Formula for the Number of Days in Each Month
by joezydeco on Friday December 05, 2014 @05:05PM
(#8707185)
Great start. Now let's add leap years. =)
[ Parent
| on HN ]
Re:A Formula for the Number of Days in Each Month
by sparkie on Saturday December 06, 2014 @01:14PM
(#8709771)
days 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
Re:A Formula for the Number of Days in Each Month
by _lce0 on Friday December 05, 2014 @05:11PM
(#8707222)
but 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)"
Re:A Formula for the Number of Days in Each Month
by joezydeco on Friday December 05, 2014 @05:56PM
(#8707417)
OP is trying to express the day count as a pure math expression. maybeLeap() probably won't do here.