除算・余剰を使わずに閏年
Posted feedbacks - Erlang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | -module(leap_year).
-import(lists).
-export([is_leap_year/1]).
list_multiple_of(B,M,[]) ->
if
B > M -> [];
true -> list_multiple_of(B,M,[B])
end;
list_multiple_of(B,M,L) ->
C = lists:nth(1,L),
if
C + B > M -> L;
true -> list_multiple_of(B,M,[C + B|L])
end.
list_leap_year(M) ->
((list_multiple_of(4,M,[]) -- list_multiple_of(100,M,[])) ++ list_multiple_of(400,M,[])) -- list_multiple_of(1000,M,[]).
is_leap_year(Y) ->
length(lists:filter(fun(X) -> X == Y end, list_leap_year(Y))) > 0.
|

greentea #5245() Rating-1/13=-0.08
see: Wikipedia 閏年
[ reply ]