Skip to content

Instantly share code, notes, and snippets.

@kouddy
Created February 20, 2015 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kouddy/be126eb637da5816bba2 to your computer and use it in GitHub Desktop.
Save kouddy/be126eb637da5816bba2 to your computer and use it in GitHub Desktop.
(define (square x) (* x x))
(define (improve guess x)
(/ (+ (/ x (square guess)) (* 2 guess)) 3))
(define (good-enough? guess improved-guess x)
(< (/ (abs (- guess improved-guess)) guess) 0.001))
(define (cubic-root-iter guess x)
(if (good-enough? guess (improve guess x) x)
guess
(cubic-root-iter (improve guess x) x)))
(define (cubic-root x)
(cubic-root-iter 1.0 x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment