Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import qualified Data.Map as M
- amount = 18
- coins = [5, 4, 2, 1]
- greedy a cs = fn a cs M.empty
- where
- fn _ [] m = m
- fn x (y:ys) m = let t = x `div` y
- in if t > 0 then fn (x-t*y) ys (M.insert y t m)
- else fn x ys m
- main :: IO ()
- main = do
- let result = greedy amount coins == M.fromList [(1,1),(2,1),(5,3)]
- putStrLn ("greedy amount coins == M.fromList [(1,1),(2,1),(5,3)] is " ++ show result)
Add Comment
Please, Sign In to add comment