Permalink
Browse files

exercise 1.8

  • Loading branch information...
bramsey committed Oct 3, 2012
1 parent 615c72d commit d5d9e62d0ab61d35beb350191aec2cb5b196a12b
Showing with 17 additions and 0 deletions.
  1. +17 −0 chapter1/1.8.rkt
View
@@ -1,3 +1,20 @@
#lang racket
(require racket/include)
(include "../common.rkt")
+
+(define (improve guess x)
+ (/ (+ (/ x (square guess))
+ (* 2 guess))
+ 3))
+
+(define (good-enough? guess x)
+ (< (abs (- (improve guess x) guess))
+ (* guess .001)))
+
+(define (cubert-iter guess x)
+ (if (good-enough? guess x)
+ guess
+ (cubert-iter (improve guess x) x)))
+
+(define (cubert x)
+ (cubert-iter 1.0 x))

0 comments on commit d5d9e62

Please sign in to comment.