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.180 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/change/Example.fs