Last active
September 28, 2015 15:49
-
-
Save johannesvogel/a202c7f3668cd639ca24 to your computer and use it in GitHub Desktop.
coins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ++ "¢ ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++"¢ ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
171 characters