Skip to content

Instantly share code, notes, and snippets.

@ngerakines
Created July 13, 2009 21:26
Show Gist options
  • Select an option

  • Save ngerakines/146459 to your computer and use it in GitHub Desktop.

Select an option

Save ngerakines/146459 to your computer and use it in GitHub Desktop.
-module(problem1).
-compile(export_all).
%% @spec solution() -> integer()
solution() ->
[spawn(Node, ?MODULE, solve, [self(), Start, Finish, 0]) || {Start, Finish, Node} <- distributor(1000)],
collector(length([node() | nodes()]), []).
collector(0, Acc) -> lists:sum(Acc);
collector(N, Acc) ->
NewAcc = receive X -> [X | Acc] end,
collector(N - 1, NewAcc).
solve(Parent, Start, Start, Acc) -> Parent ! Acc;
solve(Parent, Start, Next, Acc) ->
case is_int( Next / 3) or is_int( Next / 5) of
true -> solve(Parent, Start, Next - 1, Acc + Next);
false -> solve(Parent, Start, Next - 1, Acc)
end.
is_int(Value) ->
case Value of 0 -> true; 0.0 -> true; _ -> false end.
distributor(Max) ->
L = length([node() | nodes()]),
tp(Max / L, Max, L, [node() | nodes()], []).
tp(_SL, _Max, 0, _Nodes, Acc) -> Acc;
tp(SL, Max, L, [Node | Nodes], Acc) -> tp(SL, Max, L - 1, Nodes, [{SL * (L - 1), SL * L, Node} | Acc]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment