Created
September 24, 2013 23:30
-
-
Save Jun-Dai/6692804 to your computer and use it in GitHub Desktop.
coins in scheme
This file contains 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
(define (cc amount kinds-of-coins) | |
(if (or (< amount 0) (= kinds-of-coins 0)) 0 | |
(+ (cc amount (- kinds-of-coins 1)) | |
(if (= amount (first-denomination kinds-of-coins)) 1 0) | |
(cc (- amount (first-denomination kinds-of-coins)) kinds-of-coins)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment