Skip to content

Project Euler Problem 31

November 22, 2011

Project Euler Problem 31 solution here is a clone of one I have posted at F# snippets:

let rec change sum coins =
    if sum = 0 then [[]]
    else 
        match coins with
        | h::t -> 
            let xs = change sum t
            if sum >= h then
                let ys = change (sum - h) coins
                         |> List.map (fun xs -> h :: xs)
                List.append xs ys
            else
                xs
        | [] -> []
        
let problem031 () =
    change 200 [200;100;50;20;10;5;2;1]
    |> List.length
Advertisements

From → Project Euler

One Comment

Trackbacks & Pingbacks

  1. Project Euler Problem 76 « In F# Major

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: