Skip to content

Instantly share code, notes, and snippets.

@PatrickMcDonald
Last active August 29, 2015 14:06
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 PatrickMcDonald/ca5c9215630d3c4f6ada to your computer and use it in GitHub Desktop.
Save PatrickMcDonald/ca5c9215630d3c4f6ada to your computer and use it in GitHub Desktop.
let rec change denominations amount =
match denominations with
| [] -> 0
| _ when amount = 0 -> 1
| head :: tail when amount < head -> change tail amount
| head :: tail -> (change denominations (amount - head)) + (change tail amount)
change [50; 20; 10; 5; 2; 1] 100;;
(defun make-change (l amount)
(if l
(if (= 0 amount)
1
(if (< amount (car l))
(make-change (cdr l) amount)
(+ (make-change l (- amount (car l)))
(make-change (cdr l) amount))))
0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment