From 0d86111748933e0eb7372fe4010a091ed23e2eb6 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com>
Date: Wed, 5 May 2010 18:41:04 +0530
Subject: [PATCH] solution to 1.33

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

diff --git a/src/sicp/ex1_33.clj b/src/sicp/ex1_33.clj
new file mode 100644
index 0000000..f9ab503
--- /dev/null
+++ b/src/sicp/ex1_33.clj
@@ -0,0 +1,25 @@
+(ns sicp.ex1_33
+  (:use [sicp utils]
+	[clojure.contrib test-is]))
+
+(defn filtered-accumulate [predicate? combiner null-value term a next b]
+  (if (> a b)
+    null-value
+    (combiner (term (if (predicate? a)
+		      a
+		      null-value))
+	      (filtered-accumulate predicate?
+				   combiner
+				   null-value
+				   term
+				   (next a)
+				   next
+				   b))))
+
+(deftest test-filtered-sum-of-primes-from-1-to-10
+  (is (= (filtered-accumulate prime? + 0 identity 1 inc 10)
+	 (reduce + (filter prime? (range 1 11))))))
+
+(deftest test-filtered-prod-of-relative-primes-of-10
+  (is (= (filtered-accumulate #(= 1 (gcd % 10)) * 1 identity 1 inc 10)
+	 (reduce * (filter #(= 1 (gcd % 10)) (range 1 11))))))
\ No newline at end of file
-- 
2.45.2