Skip to content

Project Euler Problem 6

October 9, 2011

Project Euler Problem 6 solution would be provided by the aggregator part. The latter would be a classic application of fold, where accumulator will be represented by a tuple of ([sum of items],[sum of item squares]).

let problem006 () =
    [0..100]
    |> List.fold (fun (sum, sumsqrs) s -> (sum + s, sumsqrs + s * s))(0, 0)
    |> fun (sum,sumsqrs) -> sum * sum - sumsqrs
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: