#include <iostream>
#include <cassert>
using namespace std;
bool check(int idx) {
return idx <= 42;
}
int find_t(int l, int r) {
assert(check(l) == true);
//assert(check(r) == false); // this precondition is not mandatory
int max_idx_true = l; // highest known integer which satisfies check(idx) == true
int min_idx_false = r; // lowest known integer which satisfies check(idx) == false
int n = 0; // Number of iterations, not needed but helps analyzing the complexity
while (max_idx_true+1 < min_idx_false) {
++n;
int mid_idx = (max_idx_true+min_idx_false)/2;
// Analyze the algorithm in detail
// Usually this would be displayed on the standard error (cerr)
// but because ideone.com hides the standard error when everything is good
// the details are displayed on the standard output instead
cout << "Iteration #" << n;
cout << " in range [" << max_idx_true << ", " << min_idx_false << ")";
cout << " the midpoint " << mid_idx << " is " << boolalpha << check(mid_idx) << noboolalpha;
cout << endl;
if (check(mid_idx)) max_idx_true = mid_idx;
else min_idx_false = mid_idx;
}
int t = max_idx_true;
assert(check(t) == true);
assert(t+1 == r || check(t+1) == false);
return t;
}
int main() {
// Initial constants
int l = 0;
int r = 100;
int t = find_t(l, r);
cout << "The answer is " << t << endl;
return 0;
}