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.139 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.138 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.137 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.136 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.135 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.134 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.133 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.132 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.131 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.130 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.129 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.128 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.127 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.126 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.125 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.124 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.123 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.122 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.121 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.120 tracks/fsharp/exercises/change/Example.fs