(define a (vector 7 9 1 1 1 2 2 4 5 6))
(define x 4)
(define (1+ x) (+ 1 x))
(define (phase1 l r)
(let ((m (floor (/ (+ l r) 2))))
(cond
((= (vector-ref a m) x))
((>= l r) #f)
(else (or
(if (< (vector-ref a l) (vector-ref a m))
(phase2 l m) (phase1 l m))
(if (< (vector-ref a m) (vector-ref a r))
(phase2 (1+ m) r) (phase1 (1+ m) r))
))
)
)
)
(define (phase2 l r)
(let ((m (floor (/ (+ l r) 2))))
(cond
((= (vector-ref a m) x))
((>= l r) #f)
((> (vector-ref a m) x) (phase2 l m))
(else (phase2 (1+ m) r))
)
)
)
(pp (phase1 0 (- (vector-length a) 1)))