PROJECT EULER · #0406
Guessing Game
We are trying to find a hidden number selected from the set of integers
- "Your guess is lower than the hidden number" (and you incur a cost of
), or - "Your guess is higher than the hidden number" (and you incur a cost of
), or - "Yes, that's it!" (and the game ends).
Given the value of
For example, if
If we are told that 2 is higher than the hidden number (for a cost of b=3), then we are sure that "1" is the hidden number (for a total cost of 3).
If we are told that 2 is lower than the hidden number (for a cost of a=2), then our next question will be "4".
If we are told that 4 is higher than the hidden number (for a cost of b=3), then we are sure that "3" is the hidden number (for a total cost of 2+3=5).
If we are told that 4 is lower than the hidden number (for a cost of a=2), then we are sure that "5" is the hidden number (for a total cost of 2+2=4).
Thus, the worst-case cost achieved by this strategy is 5. It can also be shown that this is the lowest worst-case cost that can be achieved.
So, in fact, we have just described an optimal strategy for the given values of
Let
Here are a few examples:
Let
Find
Write-up coming later
The complete problem is available here. An approach, code, and answer will be added later.