let bsearch arr target =
  let n = Array.length arr in
  let lo = ref 0 and hi = ref (n - 1) in
  let found = ref (-1) in
  while !lo <= !hi && !found = -1 do
    let mid = (!lo + !hi) / 2 in
    if arr.(mid) = target then found := mid
    else if arr.(mid) < target then lo := mid + 1
    else hi := mid - 1
  done;
  !found

;;

let a = Array.of_list [1;3;5;7;9;11;13;15;17;19;21] in
bsearch a 13 + bsearch a 5 + bsearch a 100
