diff options
author | rsiddharth <s@ricketyspace.net> | 2018-11-22 22:54:49 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2018-11-22 22:54:49 -0500 |
commit | fc933303d5b5c15e3f912f74dc1af6c1ba3118c5 (patch) | |
tree | 49528537e1ae8d435ace8e44bdee3c2cd26ac5e6 | |
parent | 197c46b80ec621938fbac8e3926fa2efb83aa07f (diff) |
Add (net ricketyspace sicp two nineteen).
-rw-r--r-- | net/ricketyspace/sicp/two/nineteen.scm | 26 |
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)) |