Skip to content

Instantly share code, notes, and snippets.

@davejachimiak
Created October 3, 2014 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davejachimiak/942f7d25c4f4716e0771 to your computer and use it in GitHub Desktop.
Save davejachimiak/942f7d25c4f4716e0771 to your computer and use it in GitHub Desktop.
tree-recursive solution to the counting change problem, pg. 41 SICP
countChange :: Integer -> [Integer] -> Integer
countChange amount denominations
| null denominations || amount < 0 = 0
| amount == 0 = 1
| otherwise = countChange amount (tail denominations) + countChange (amount - head denominations) denominations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment