challenges/e1.erl

14 lines
486 B
Erlang

-module(e1).
-export([e1/0]).
add_list([], Acc) -> Acc;
add_list([X| Tail], Acc) -> add_list(Tail, Acc+X).
find_3_5_divisibles(Start, Max) -> find_3_5_divisibles(Start, Max, []).
find_3_5_divisibles(Max, Max, Acc) -> Acc;
find_3_5_divisibles(Start, Max, Acc) when Start rem 3 == 0; Start rem 5 == 0 -> find_3_5_divisibles(Start+1, Max, [Start |Acc]);
find_3_5_divisibles(Start, Max, Acc) -> find_3_5_divisibles(Start+1, Max, Acc).
e1() -> add_list(find_3_5_divisibles(2, 1000), 0).