Sha256: 782505d3e3850f386c9a31e3a31fd129a69191e36204ae0d5934660dc3b093a7
Contents?: true
Size: 1.39 KB
Versions: 216
Compression:
Stored size: 1.39 KB
Contents
module BookStore let private costPerGroup groupSize = let discountPercentage = match groupSize with | 1 -> 0. | 2 -> 5. | 3 -> 10. | 4 -> 20. | 5 -> 25. | _ -> failwith "Invalid group size" 8. * (groupSize |> float) * (100. - discountPercentage) / 100. let private remove n list = let rec removeTail n list acc = match list with | x::xs when x = n -> List.append (List.rev acc) xs | x::xs -> removeTail n xs (x::acc) | [] -> List.rev acc removeTail n list [] let rec private calculateTotalCostHelper books priceSoFar = match books |> List.length with | 0 -> priceSoFar | _ -> let groups = books |> List.groupBy id |> List.map fst let prices = [1 .. groups |> List.length] |> List.map (fun i -> let itemsToRemove = groups |> List.take i let remaining = itemsToRemove |> List.fold (fun state t -> remove t state) books calculateTotalCostHelper remaining (priceSoFar + costPerGroup i) ) prices |> List.min let calculateTotalCost books = calculateTotalCostHelper books 0.
Version data entries
216 entries across 216 versions & 1 rubygems