There exists exactly one Pythagorean triplet for which `a` + `b` + `c` = 1000.

Find the product `abc`.

module Problem9 =
let max = 1000
let isPythagoreanTriple (a,b,c) = a*a + b*b = c*c
let product (a,b,c) = a*b*c
let triples = seq{for c in 1 .. max do
for a in 1 .. (max - c) do
yield (a ,(max - c - a), c)}
let ans = Seq.find isPythagoreanTriple triples |> product

I think it would be more efficient to do this by generating Pythagorean triples, rather than numbers summing to 1000, but this took all of 10 seconds to write up, and perhaps 10 µs to run, so I’m going to use this solution and move on.

### Like this:

Like Loading...

*Related*