Skip to content

Project Euler Problem 38

November 22, 2011

Project Euler Problem 38 solution space is limied from above: the max candidate producing 9-digit concatenated product is 9999 as 10000 produces 10-digit concatenated product.

With this in mind here is a brute-force solution:

let is1To9Pandigital (s: string) =
        let ss = s |> Set.ofSeq
        s.Length = 9 && Set.count ss = 9
        && ss.MinimumElement = '1' && ss.MaximumElement = '9'
let concatenatedProduct n =
    [for i = 1 to 9 do yield string(n * i)]
    |> List.fold (fun (res:string) x ->
           if res.Length < 9 then res + x else res) ""

let problem038 () =
    [1..9999]
    |> List.map concatenatedProduct
    |> List.filter is1To9Pandigital
    |> List.max
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: