Skip to content

Instantly share code, notes, and snippets.

@ryanbriones
Forked from jimweirich/gist:189270
Created September 25, 2009 04:17
Show Gist options
  • Save ryanbriones/193298 to your computer and use it in GitHub Desktop.
Save ryanbriones/193298 to your computer and use it in GitHub Desktop.
SICP Exercise 1.8
;; SICP 1.8
;; Fork me. Solve me.
(define (cube x) (* x x x))
(define (improve y x)
(/ (+ (/ x (* y y)) (* 2 y)) 3))
(define (good-enough? guess x)
(< (abs (- (cube guess) x)) 0.001))
(define (cube-iter guess x)
(if (good-enough? guess x)
guess
(cube-iter (improve guess x)
x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment