Last active
August 29, 2015 14:06
-
-
Save PatrickMcDonald/ca5c9215630d3c4f6ada 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
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;; |
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
(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