Puzzle 69 |The Number Game
Ankur and Vijay are fond of playing Number games. In one of the games, Ankur has to choose a number X, such that X belongs to [1, 10000] . Vijay has to guess the chosen number as soon as possible. Ankur will let Vijay know whether his guess is smaller than, larger than or equal to the number. The warning is that Vijay loses the game if his guess is larger than Ankur’s chosen number two or more times.
Q1. How to make guesses, and how many guesses are necessary?
Q2. What if Ankur is allowed to pick a very large positive number without any given limits ? .
Both the problems can be treated in the following ways:
When Ankur chooses a number between 1 and n, here n=10000, Vijay should start guessing √n, 2√n, 3√n, 4√n, and so on. The first time his guess exceeds Ankur’s number, the range of numbers has been narrowed down to √n numbers; he then starts guessing sequentially in that range.
Ans2: If Ankur guesses an arbitrarily large number n, then Vijay may guess 1, 4, 9, 16, 25, and so on, to discover k such that Ankur’s number lies between k^2 and (k+1)2. Then guess k2+1, k2+2, k2+3 and so on. On the whole, this requires O(√n) steps.
This puzzle is contributed by Praveer Satyam. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above