summaryrefslogtreecommitdiffstats
path: root/net/ricketyspace
diff options
context:
space:
mode:
Diffstat (limited to 'net/ricketyspace')
-rw-r--r--net/ricketyspace/sicp/two/nineteen.scm26
1 files changed, 26 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/two/nineteen.scm b/net/ricketyspace/sicp/two/nineteen.scm
new file mode 100644
index 0000000..e4f7259
--- /dev/null
+++ b/net/ricketyspace/sicp/two/nineteen.scm
@@ -0,0 +1,26 @@
+;;;; License: CC0-1.0
+
+(define-module (net ricketyspace sicp two nineteen)
+ #:export (us-coins uk-coins cc))
+
+(define us-coins (list 50 25 10 5 1))
+(define uk-coins (list 100 50 20 10 5 2 1 0.5))
+
+(define (cc amount coin-values)
+ (cond ((= amount 0) 1)
+ ((or (< amount 0) (no-more? coin-values)) 0)
+ (else
+ (+ (cc amount
+ (except-first-denomination coin-values))
+ (cc (- amount
+ (first-denomination coin-values))
+ coin-values)))))
+
+(define (no-more? coin-values)
+ (null? coin-values))
+
+(define (except-first-denomination coin-values)
+ (cdr coin-values))
+
+(define (first-denomination coin-values)
+ (car coin-values))