Skip to content

Instantly share code, notes, and snippets.

@pjrt
Last active August 16, 2016 14:58
Show Gist options
  • Save pjrt/350627df3db1a89bb6aa3afb19d13598 to your computer and use it in GitHub Desktop.
Save pjrt/350627df3db1a89bb6aa3afb19d13598 to your computer and use it in GitHub Desktop.
countChg :: Int -> [Int] -> Int
countChg 0 _ = 1 -- There is only one way of counting an amount of 0
countChg _ [] = 0 -- There are 0 ways to count for no coins
countChg amt coins@(c:cs)
| amt < 0 = 0 -- This branch failed, we got something less than 0
| otherwise = countChg amt cs + countChg (amt - c) coins -- Branch out into a branch with one less coin and
-- a branch with the same number of coins but one coin
-- reduced from the amount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment