Created
September 19, 2012 19:26
-
-
Save Ummon/3751687 to your computer and use it in GitHub Desktop.
Haskell > Scala
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
countChange :: Int -> [Int] -> Int | |
countChange money coins = | |
let | |
applyFactors factors = (if (sum $ zipWith (*) coins factors) == money then 1 else 0) + | |
if all (== money) factors then 0 | |
else | |
applyFactors (nextFactors factors) | |
where | |
nextFactors (x : xs) | |
| x == money = 0 : (nextFactors xs) | |
| otherwise = (x + 1) : xs | |
in | |
applyFactors $ replicate (length coins) 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment