Skip to content

Instantly share code, notes, and snippets.

@cohalz
Created December 8, 2014 09:15
Show Gist options
  • Select an option

  • Save cohalz/f87bdd21d47f538405ef to your computer and use it in GitHub Desktop.

Select an option

Save cohalz/f87bdd21d47f538405ef to your computer and use it in GitHub Desktop.
(define (improve guess x)
(average guess (/ x guess)))
(define (average x y)
(/ (+ x y) 2))
(define (square x) (* x x))
(define (good-enough? guess iguess)
(= (/ guess iguess) 1))
(define (sqrt-iter guess x)
(if (good-enough? guess (improve guess x))
guess
(sqrt-iter (improve guess x) x)))
(define (sqrt x)
(sqrt-iter 1.0 x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment