Guest User

Untitled

a guest
Mar 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. import qualified Data.Map as M
  2.  
  3. amount = 18
  4.  
  5. coins = [5, 4, 2, 1]
  6.  
  7. greedy a cs = fn a cs M.empty
  8. where
  9. fn _ [] m = m
  10. fn x (y:ys) m = let t = x `div` y
  11. in if t > 0 then fn (x-t*y) ys (M.insert y t m)
  12. else fn x ys m
  13.  
  14. main :: IO ()
  15. main = do
  16. let result = greedy amount coins == M.fromList [(1,1),(2,1),(5,3)]
  17. putStrLn ("greedy amount coins == M.fromList [(1,1),(2,1),(5,3)] is " ++ show result)
Add Comment
Please, Sign In to add comment