Sha256: 81a706b419e52fd9e56ea499fbf1f00753a8ac842839c2582a45fa727bd27efd

Contents?: true

Size: 594 Bytes

Versions: 134

Compression:

Stored size: 594 Bytes

Contents

module Change

let minimalCoins coins map target =
    coins
    |> List.filter (fun x -> x <= target) 
    |> List.choose (fun x -> 
        match Map.tryFind (target - x) map with
        | Some y -> Some(x :: y)
        | None -> None)   
    |> List.sortBy List.length
    |> List.tryHead 

let updateMinimalCoinsMap coins map target = 
    match minimalCoins coins map target with
    | Some x -> Map.add target x map
    | None   -> map

let findFewestCoins coins target = 
    [1..target]
    |> List.fold (updateMinimalCoinsMap coins) (Map.ofList [(0, [])])
    |> Map.tryFind target

Version data entries

134 entries across 134 versions & 1 rubygems

Version Path
trackler-2.2.1.78 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.77 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.76 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.75 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.74 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.73 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.72 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.71 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.70 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.69 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.68 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.67 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.66 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.65 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.64 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.63 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.62 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.61 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.60 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.59 tracks/fsharp/exercises/change/Example.fs