]> git.rkrishnan.org Git - sicp.git/blobdiff - src/sicp/ch1_3.clj
solutions to 4.50..4.54
[sicp.git] / src / sicp / ch1_3.clj
index 5aaf159db314c146bdf1e862fb278a5a787acc45..355cdc416f5f978cffac121376fcda5606a01054 100644 (file)
 
 (defn newton-sqrt [x]
   (newton-method (fn [y] (- (square y) x))
-                1.0))
\ No newline at end of file
+                1.0))
+
+(defn fixed-point-of-transform [g transform guess]
+  (fixed-point (transform g) guess))
+
+(defn sqrt1 [x]
+  (fixed-point-of-transform (fn [y] (/ x y))
+                           average-damp
+                           1.0))
+
+(defn sqrt2 [x]
+  (fixed-point-of-transform (fn [y] (- (square y) x))
+                           newton-transform
+                           1.0))
\ No newline at end of file