Two-number guessing game

468 Views Asked by At

We play a variant of the classical number guessing game. The rules is as follows:

  1. There are two integers $a,b$ to be guessed. It is guaranteed that $1\leq a < b \leq n$.
  2. Each round I can guess an integer $p$. The possible responses are:
    • $p<a$
    • $a=p$
    • $a<p<b$
    • $p=b$
    • $b<p$

How can I pick $p$ each round so that I can guess both $a$ and $b$ correctly in fewest rounds?

1

There are 1 best solutions below

0
On

I would guess that using a binary search algorithm would guarantee the fastest result. First select the integer part of the midpoint number $\frac{n}{2}$. If a is below this, then select the midpoint of the bottom half. Continue selecting the midpoint of the section that a is forced into, until a is found. Then repeat with the upper half to find b.