15 lines
257 B
Scheme
15 lines
257 B
Scheme
|
(define (sqrt x)
|
||
|
(define tolerance 0.00001)
|
||
|
(define (good-enough? y)
|
||
|
(< (abs (- (* y y) x)) tolerance))
|
||
|
(define (improve y)
|
||
|
(average (/ x y) y))
|
||
|
(define (try y)
|
||
|
(if (good-enough? y)
|
||
|
y
|
||
|
(try (improve y))))
|
||
|
(try 1))
|
||
|
(sqrt 13)
|
||
|
|
||
|
|