Last active
August 16, 2016 14:58
-
-
Save pjrt/350627df3db1a89bb6aa3afb19d13598 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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