fork download
  1. ; reluctant search
  2.  
  3. (define (research x xs i j)
  4. (if (> i j)
  5. -1
  6. (if (= i j)
  7. (if (= x (vector-ref xs i))
  8. i
  9. -1)
  10. (let ((m (quotient (+ i j) 2)))
  11. (if (<= x (vector-ref xs m))
  12. (let ((k (research x xs (+ m 1) j)))
  13. (if (= k -1)
  14. (research x xs i m)
  15. k)))
  16. (let ((k (research x xs i m)))
  17. (if (= k -1)
  18. (research x xs (+ m 1) j)
  19. k))))))
  20.  
  21. (display (research 3 '#(1 2 3 5 6) 0 4)) (newline)
  22. (display (research 4 '#(1 2 3 5 6) 0 4)) (newline); your code goes here
Success #stdin #stdout 0.03s 8616KB
stdin
Standard input is empty
stdout
2
-1