Skip to content

Project Euler Problem 40

November 22, 2011

The solution of Project Euler Problem 40 is straightforward; first I build the fraction’s recording represented as int array of digits, then calculate the result:

open System

let concatSeq len ss =
    new string (ss
        |> Seq.collect (fun s ->
            Seq.ofArray <| s.ToString().ToCharArray())
        |> Seq.take len
        |> Seq.toArray)

let digits = Seq.initInfinite (fun n -> n) |> concatSeq 1000001

let problem040 () =
    [1;10;100;1000;10000;100000;1000000]
    |> List.fold (fun result x ->
        result * Int32.Parse(string digits.[x])) 1
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: