Objective
Implement a function that locates key in an increasing sequence you can only read one element at a time through the callback at, spending at most 24 reads.
Steps
$ binary_search(7, 8, at) over {2, 4, 6, 8, 10, 12, 14}
idx=3 probes<=24
$ binary_search(5, 3, at) over {1, 3, 3, 3, 5}
idx=1 probes<=24
$ binary_search(7, 9, at) over {2, 4, 6, 8, 10, 12, 14}
idx=-1 probes<=24
$ binary_search(1000000, 1999998, at) with at(i) = i * 2
idx=999999 probes<=24
$ the same call, answered by reading index 0, then 1, then 2, and so on
idx=999999 probes=1000000
Expected files
Allowed functions
None. Write every helper yourself.
Allowed headers

Objective
Implement a function that locates key in an increasing sequence you can only read one element at a time through the callback at, spending at most 24 reads.
Steps
$ binary_search(7, 8, at) over {2, 4, 6, 8, 10, 12, 14}
idx=3 probes<=24
$ binary_search(5, 3, at) over {1, 3, 3, 3, 5}
idx=1 probes<=24
$ binary_search(7, 9, at) over {2, 4, 6, 8, 10, 12, 14}
idx=-1 probes<=24
$ binary_search(1000000, 1999998, at) with at(i) = i * 2
idx=999999 probes<=24
$ the same call, answered by reading index 0, then 1, then 2, and so on
idx=999999 probes=1000000
Expected files
Allowed functions
None. Write every helper yourself.
Allowed headers

Tests
Run the tests to grade your code