sicp-answer~> 1-8

按照题目提示写一遍即可, 把之前的 sqrt 换成 curt, 修改下 improve 函数即可:
(sqrt: square root, 平方根)
(curt: cube root, 立方根)

(define (curt x)
  (curt-iter 1.0 x))

(define (curt-iter guess x)
  (if (good-enough? guess (improve guess x))
    (improve guess x)
    (curt-iter (improve guess x) x)))

(define (square x)
  (* x x))

(define (improve guess x)
    (/ (+ (/ x (square guess)) (* 2 guess))
       3))

(define (good-enough? old-guess guess)
  (> 0.01
    (/ (abs (- guess old-guess))
        old-guess)))

上一篇: 1-7
下一篇: 1-9