From 1535cff172539fd8c0dc5ab075bb38d4d63f3a45 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com>
Date: Thu, 25 Mar 2010 08:57:04 +0530
Subject: [PATCH] exercise 1.8 solution.

---
 chapter1/ch1_1.clj | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/chapter1/ch1_1.clj b/chapter1/ch1_1.clj
index bcb6329..118022e 100644
--- a/chapter1/ch1_1.clj
+++ b/chapter1/ch1_1.clj
@@ -235,4 +235,30 @@ user> (sqrt 9)
 user> (sqrt 81)
 9.000000000007091
 
-;; exercise 1.8:
+;; exercise 1.8: cube root
+(defn cube [x]
+  (* x x x))
+
+(defn improve [guess x]
+  (/ (+ (/ x (square guess)) (* 2 guess)) 3))
+
+(defn cubert-iter [old-guess new-guess x]
+  (if (good-enough? old-guess new-guess x)
+    new-guess
+    (cubert-iter new-guess (improve new-guess x)
+		 x)))
+
+(defn cubert [x]
+  (cubert-iter x 1.0 x))
+
+user> (cubert (cube 2))
+2.000000000012062
+user> (cubert (cube 10))
+10.000000000000002
+user> (cubert (cube 9))
+9.000000000053902
+user> (cubert (cube 0.001))
+0.001000000000000962
+user> (cubert (cube 0.0001))
+1.000000000000001E-4
+user> 
\ No newline at end of file
-- 
2.45.2