Skip to content

Project Euler Problem 33

November 22, 2011

Project Euler Problem 33.

It is easy to notice that these four sought fractions should be solutions for the equation

10*z*(x – y) = y*(x – z)
where x,y,z – digits 1..9, and y < z

From here the solution is straightforward:

let problem033 () =
    [for x = 1 to 9 do
        for y = 1 to 9 do
            for z = 1 to 9 do
                if 10*z*(x - y) = y * (x - z) && y > z then
                    //printfn "%d/%d" (10*z + x) (10*x + y)
                    yield (10*z + x), (10*x + y)
    ]
    |> Seq.fold (fun (numerator, denominator) (x,y) ->
                    (numerator*x, denominator*y)) (1,1)
    |> fun (numerator,denominator) -> denominator/numerator

Uncommenting printfn statement above allows to reveal these four unorthodox fractions.

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: