Created
April 2, 2012 07:51
-
-
Save stepankuzmin/2281482 to your computer and use it in GitHub Desktop.
Project Euler. Problem 9.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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