Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(define (iterative-improve good-enough? improve first-guess)
((lambda (f) (f f first-guess))
(lambda (f guess)
(if (good-enough? guess) guess (f f (improve guess))))))
(define (iterative-sqrt x)
(iterative-improve (lambda (y) (< (abs (- (square y) x)) 0.001))
(lambda (y) (average y (/ x y)))
(iterative-sqrt 100) ; 10.000000000139897
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.