From d2bbe9d4146b59a97ec05adefc898e6581735d02 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com>
Date: Mon, 21 Jun 2010 18:17:13 +0530
Subject: [PATCH] solution to 2.19

---
 src/sicp/ex2_19.clj | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 src/sicp/ex2_19.clj

diff --git a/src/sicp/ex2_19.clj b/src/sicp/ex2_19.clj
new file mode 100644
index 0000000..645a4c6
--- /dev/null
+++ b/src/sicp/ex2_19.clj
@@ -0,0 +1,28 @@
+(ns sicp.ex2_19
+  (:use [sicp utils]
+	[clojure test]))
+
+(declare no-more? first-denomination except-first-denomination)
+
+(defn 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))))
+
+(defn no-more? [lst] (empty? lst))
+(defn first-denomination [lst] (first lst))
+(defn except-first-denomination [lst] (rest lst))
+
+;; tests
+(def *us-coins* (list 50 25 10 5 1))
+(def *uk-coins* (list 100 50 20 10 5 2 1 0.5))
+
+(deftest test-us-coins-change-for-100-cents
+  (are [x y] [= x y]
+       (cc 100 *us-coins*) 292
+       (cc 100 *uk-coins*) 104561))
\ No newline at end of file
-- 
2.45.2