Skip to content

Instantly share code, notes, and snippets.

@jbochi
Created January 17, 2012 01:17
Show Gist options
  • Save jbochi/1623970 to your computer and use it in GitHub Desktop.
Save jbochi/1623970 to your computer and use it in GitHub Desktop.
Cube root in lisp (SICP ex 1.8)
(define (croot x)
(croot-iter 1.00 x))
(define (croot-iter guess x)
(if (good-enough? guess x)
guess
(croot-iter (improve guess x)
x)))
(define (improve guess x)
(/ (+ (/ x (square guess))
(* 2 guess))
3))
(define (cube x)
(* x x x))
(define (good-enough? guess x)
(< (abs (- (cube guess) x))
0.001))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment