sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit fc933303d5b5c15e3f912f74dc1af6c1ba3118c5
parent 197c46b80ec621938fbac8e3926fa2efb83aa07f
Author: rsiddharth <s@ricketyspace.net>
Date:   Thu, 22 Nov 2018 22:54:49 -0500

Add (net ricketyspace sicp two nineteen).

Diffstat:
net/ricketyspace/sicp/two/nineteen.scm | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/net/ricketyspace/sicp/two/nineteen.scm 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))