-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathp9.erl
More file actions
16 lines (13 loc) · 686 Bytes
/
p9.erl
File metadata and controls
16 lines (13 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-module(p9).
-export([answer/0]).
%% A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^(2) + b^(2) = c^(2)
%% For example, 3^(2) + 4^(2) = 9 + 16 = 25 = 5^(2).
%% There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product a*b*c.
answer() ->
[{X, Y, Z} | _Rest] = [ {A, B, C} || C <- lists:seq(1, 1000),
B <- lists:seq(1, 499),
A <- lists:seq(1, 498),
(A*A + B*B) =:= (C*C),
(A+B+C) =:= 1000,
A < B ],
X*Y*Z.