Skip to content

Instantly share code, notes, and snippets.

@johannesvogel
Last active September 28, 2015 15:49
Show Gist options
  • Save johannesvogel/a202c7f3668cd639ca24 to your computer and use it in GitHub Desktop.
Save johannesvogel/a202c7f3668cd639ca24 to your computer and use it in GitHub Desktop.
coins
main = do
money <- getLine
mapM putStr $ coins [200, 100, 50, 20, 10, 5, 2, 1] (read money)
coins [] _ = []
coins (x:xs) y
| x <= y = (coin x) : coins (x:xs) (y-x)
| x > y = coins xs y
coin x
| x > 99 = ((show $ x `div` 100) ++ "€ ")
| x <= 99 = (show x ++ "¢ ")
main=do m<-getLine;mapM putStr$a[200,100,50,20,10,5,2,1](read m)
a[]_=[];a(x:xs)y|x<=y=(b x):a(x:xs)(y-x)|x>y=a xs y
b x|x>99=((show$x`div`100)++"€ ")|x<=99=(show x++"¢ ")
@johannesvogel
Copy link
Author

171 characters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment