Phil Bewig <pbewig@swbell.net> wrote:
+---------------
| Does this work?
|
| (define (isqrt a)
| (if (<= a 0)
| 0 ; punt
| (let loop ((x 1))
| (let ((new-x (quotient (+ x (quotient a x)) 2)))
| (if (= x new-x)
| x
| (loop new-x))))))
+---------------
Unfortunately, it loops forever when given an argument of
"(- (* x x) 1)", for any "x", e.g., try (isqrt 99).
[Why is left as an exercise for the reader...]
-Rob
-----
Rob Warnock, PP-ASEL-IA <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607