Skip to content

Project Euler Problem 47

November 26, 2011

Project Euler Problem 47 solution:

let primeFactors n =
    let rec factorize n f =
        seq {
        if n <= f then
            yield f
        else
            match n%f with
            | 0 -> yield f; yield! factorize (n/f) f
            | _ -> yield! factorize n (f + 1)
        }

    factorize n 2

let fourPrimes (a: int array) =
    primeFactors a.[0] |> set |> Set.count = 4 &&
    primeFactors a.[1] |> set |> Set.count = 4 &&
    primeFactors a.[2] |> set |> Set.count = 4 &&
    primeFactors a.[3] |> set |> Set.count = 4

let problem047 () =
    Seq.initInfinite id
    |> Seq.windowed 4
    |> Seq.find fourPrimes
    |> Array.get <| 0
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: