Skip to content

Project Euler Problem 9

October 12, 2011

Project Euler Problem 9 solution is very straightforward:

  1. Make sequence of tuples where a < b < c and a + b + c = 1000
  2. Find from this sequence one that is Pythagorean, i.e. a2 + b2 = c2
  3. Return the product of tuple members
let tripletsSum1000 =
    seq {
    for a in 1 .. 333 do
        for b in a + 1 .. 499 do
            let c = 1000 - b - a
            if a < b && b < c then
                 yield (a,b,c)
     }
let problem009 () =
     tripletsSum1000
     |> Seq.find (fun (a,b,c) -> a * a + b * b = c * c)
     |> fun (a,b,c) -> a*b*c
Advertisements

From → Project Euler

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: