Project Euler Problem #9

Home/Uncategorized/Project Euler Problem #9

I’m beginning to learn F# and the best way for me to go about that is to start applying it. There are some interesting computational problems over at Project Euler . This post is the continuation of a series of posts each involving a separate Project Euler problem. This post involves solutions to Project Euler problem #9.

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
let triplet =
    seq {
    for a = 0 to 332 do // since a < b < c the max a can be is 332
        for b = a+1 to 499 do // since b < c the max b can be is 499
            let c = 1000 - a - b
            if a*a + b*b = c*c then yield (a, b, c)
    }
    |> Seq.hd

Leave a Comment