Skip to content

Instantly share code, notes, and snippets.

@Ummon
Created September 19, 2012 19:26
Show Gist options
  • Save Ummon/3751687 to your computer and use it in GitHub Desktop.
Save Ummon/3751687 to your computer and use it in GitHub Desktop.
Haskell > Scala
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