Skip to content

Project Euler Problem 13

October 20, 2011

Project Euler Problem 13 is utterly straightforward: parse each line into a bigint, then upon aggregation add them together and take first 10 digits of the sum:

open System.IO

let readLines (filePath: string) =
    seq {
        use sr = new StreamReader (filePath)
        while not sr.EndOfStream do
            yield bigint.Parse(sr.ReadLine ())

let problem013 () =
    readLines @"..\..\..\Datafiles\"
    |> (Seq.sum >> sprintf "%A" >> fun x -> x.Substring(0,10))

From → Project Euler

Leave a Comment

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: