Skip to content

Instantly share code, notes, and snippets.

@jochasinga
Created November 19, 2018 12:34
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 jochasinga/4487987f3fd439e10d1fae3f73ddc489 to your computer and use it in GitHub Desktop.
Save jochasinga/4487987f3fd439e10d1fae3f73ddc489 to your computer and use it in GitHub Desktop.
Newton's method of finding a square root
(define (square-of x)
(define (average x y)
(/ (+ x y) 2))
(define (improve guess x)
(average guess (/ x guess)))
(define (good-enough? guess x)
(< (abs (- (square-of guess) x)) 0.001))
(define (sqrt-iter guess x)
(if (good-enough? guess x)
guess
(sqrt-of (improve guess x)
x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment