Skip to content

Instantly share code, notes, and snippets.

@superchris
Forked from jimweirich/gist:189270
Created September 25, 2009 03:15
Show Gist options
  • Save superchris/193266 to your computer and use it in GitHub Desktop.
Save superchris/193266 to your computer and use it in GitHub Desktop.
(define (cubert x)
(define (improve guess x)
(/
(+ (/ x (* guess guess)) (* 2 guess))
3)
)
(define (cube x)
(* x x x))
(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)))
(cube-iter 1.0 x)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment