diff options
author | rsiddharth <s@ricketyspace.net> | 2016-11-12 02:52:06 +0000 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2016-11-12 02:52:06 +0000 |
commit | 5bf0b73c2aff8613c3db3188356d4735ca6506a3 (patch) | |
tree | 312152a0ed927c71e87abf52a97e69842db9039c /one | |
parent | 4cb8f74731ee1277404085746d8e1da7cd549476 (diff) |
add one/fourteen.scm
Diffstat (limited to 'one')
-rw-r--r-- | one/fourteen.scm | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/one/fourteen.scm b/one/fourteen.scm new file mode 100644 index 0000000..47156c7 --- /dev/null +++ b/one/fourteen.scm @@ -0,0 +1,29 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; <https://creativecommons.org/licenses/by-sa/4.0/>. + +;;; source from section 1.2.2 + +(define-module (one fourteen) + #:export (count-change + cc + first-denomination)) + +(define (count-change amount) + (cc amount 5)) + +(define (cc amount kinds-of-coins) + (cond ((= amount 0) 1) + ((or (< amount 0) (= kinds-of-coins 0)) 0) + (else (+ (cc amount + (- kinds-of-coins 1)) + (cc (- amount + (first-denomination kinds-of-coins)) + kinds-of-coins))))) + +(define (first-denomination kinds-of-coins) + (cond ((= kinds-of-coins 1) 1) + ((= kinds-of-coins 2) 5) + ((= kinds-of-coins 3) 10) + ((= kinds-of-coins 4) 25) + ((= kinds-of-coins 5) 50))) |