Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Created April 2, 2012 07:51
Show Gist options
  • Save stepankuzmin/2281482 to your computer and use it in GitHub Desktop.
Save stepankuzmin/2281482 to your computer and use it in GitHub Desktop.
Project Euler. Problem 9.
-module(euler9).
-compile(export_all).
start() ->
start(1, 2, 1000, []).
start(A, Max, Max, Acc) ->
start(A+1, A+2, Max, Acc);
start(Max, _B, Max, Acc) ->
Acc;
start(A, B, Max, Acc) ->
Sqrt = math:sqrt(A*A+B*B),
C = round(Sqrt),
case C == Sqrt of
true -> case A+B+C == Max of
true -> A*B*C;
false -> start(A, B+1, Max, [{A, B, C}|Acc])
end;
false -> start(A, B+1, Max, Acc)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment