Created
May 27, 2011 22:28
-
-
Save mauricioszabo/996323 to your computer and use it in GitHub Desktop.
Coding Dojo 27-maio-2011
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 = | |
putStrLn (show $ trocoPara 50) | |
trocoPara quantia = | |
let todasCombinacoes = todasPossibilidades (quantia `div` (last todasMoedas)) [] | |
in filter (\c -> (sum c) == quantia ) todasCombinacoes | |
todasPossibilidades num ps = | |
if num == 0 then ps | |
else concat [ (possibilidades num), (todasPossibilidades (num - 1) ps) ] | |
possibilidades 1 = concat [sequence [todasMoedas]] | |
possibilidades num = | |
let anterior = possibilidades (num - 1) | |
in [ a:b | a <- todasMoedas, b <- anterior, a >= b !! 0 ] | |
todasMoedas = [100, 50, 25, 10, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment