; look and say, revisited
(define cs '(-6 3 -6 12 -4 7 -7 1 0 5 -2 -4 -12 2 7
12 -7 -10 -4 3 9 -7 0 -8 14 -3 9 2 -3 -10 -2 -6 1
10 -3 1 7 -7 7 -12 -5 8 6 10 -8 -8 -7 -3 9 1 6 6 -2
-3 -10 -2 3 5 2 -1 -1 -1 -1 -1 1 2 2 -1 -2 -1 0 1))
(define (horner x cs)
(let loop ((z 0) (cs (reverse cs)))
(if (null? cs) z
(loop (+ (* x z) (car cs)) (cdr cs)))))
(define (bisect lo hi eps cs)
(let loop ((lo lo) (hi hi))
(if (< (abs (- hi lo)) eps)
(exact->inexact (/ (+ lo hi) 2))
(let* ((mid (/ (+ lo hi) 2))
(fmid (horner mid cs)))
(if (negative? fmid)
(loop mid hi)
(loop lo mid))))))
(display (bisect 1 2 1e-15 cs))