Sha256: db693404aae6db58e2ac0a249db284ae81b1efa80dd0b9466576d46e47975e65

Contents?: true

Size: 503 Bytes

Versions: 262

Compression:

Stored size: 503 Bytes

Contents

module Change

let minimalCoins coins map target =
    coins
    |> List.filter (fun x -> x <= target)
    |> List.map (fun x -> x :: Map.find (target - x) map)
    |> 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 change target coins = 
    [1..target]
    |> List.fold (updateMinimalCoinsMap coins) (Map.ofList [(0, [])])
    |> Map.tryFind target

Version data entries

262 entries across 262 versions & 1 rubygems

Version Path
trackler-2.2.1.44 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.43 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.42 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.41 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.40 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.39 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.38 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.37 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.36 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.35 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.34 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.33 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.32 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.31 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.30 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.29 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.28 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.27 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.26 tracks/fsharp/exercises/change/Example.fs
trackler-2.2.1.25 tracks/fsharp/exercises/change/Example.fs