From fc933303d5b5c15e3f912f74dc1af6c1ba3118c5 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 22 Nov 2018 22:54:49 -0500 Subject: Add (net ricketyspace sicp two nineteen). --- net/ricketyspace/sicp/two/nineteen.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 net/ricketyspace/sicp/two/nineteen.scm (limited to 'net/ricketyspace') 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)) -- cgit v1.2.3