Guess a number

Alice thinks of a natural number between 1 and 10,000 (inclusive). Bob must guess it. Each time Bob makes a guess, Alice tells him whether it is too small, too big, or correct. If it is not correct, Bob guesses again.

How many guesses does Bob need in order to correctly identify Alice's number?

Clarification: It is not enough for Bob to figure out Alice's number. He must actually say it. That is, Bob's last guess must be the right answer.


From Guessing games


The answer is 14.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

Varsha Dani
Oct 30, 2018

Suppose Alice is going to choose a number between \ell and h h (both inclusive), which is a set of h + 1 h-\ell+1 numbers Clearly the number of guesses required when = h \ell = h is 1.

Now suppose < h \ell < h , and suppose Bob guesses some number k k with k h \ell \le k \le h . If k k happens to be Alice's number, then Bob is done, but otherwise space of possibilities is divided into two: \ell to k 1 k-1 and k + 1 k+1 to h h . In the worst case, Alice's number is in the larger of these two intervals, so that the number of guesses Bob needs is one more than the number of guesses needed for the larger of the two intervals. (One more to account for his first guess which was k k ). Clearly this will be minimized if Bob makes the two intervals as close as possible in size. That is, they are either of equal size or their sizes differ by 1.

Thus, if we start with an interval of length N N then Bob's best strategy is to have his guess divide the interval into two intervals, one of size N / 2 \lfloor N/2 \rfloor and the other either the same size or one less.

Each time the length of the interval is halved, Bob has used one guess. And he needs one guess for an interval of length 1. An easy induction now shows that the number of guesses required for an interval of length N N is log 2 ( N ) + 1 \lfloor\log_2(N)\rfloor+1 . Note that this is both the number of guesses Bob needs in the worst case, as well as a sufficient number in any case, since we have demonstrated a strategy for Bob.

Plugging in N = 10 , 000 N= 10,000 , we get log 2 ( 10 , 000 ) + 1 = 14 \lfloor\log_2(10,000)\rfloor +1 = \fbox{14}

Parth Sankhe
Oct 30, 2018

This is just a guess!

Bob just keeps on guessing half of what the sample space is. [E.g At first, he guesses 5000, then knowing whether its greater or smaller he guesses 7,500 or 2,500 respectively.] At the end of the 12th try, there would be 2 cards left [ f l o o r ( 10 , 000 2 12 ) = 2 floor (\frac {10,000}{2^{12}})=2 ]. Then he would need a maximum of just 2 more guesses, giving us the answer of 14 .

Nice. But who is Brian? :)

Also, technically your solution only shows 14 is achievable, not that it is needed in the worst case.

Varsha Dani - 2 years, 7 months ago

Log in to reply

14 is the number of guesses if he divides by 2 every time (which is the smart thing to do). But the worst case scenario is 9998 guesses.

Gabrielle Fisher - 2 years, 7 months ago

Log in to reply

I was referring to the worst case over Alice's choice of number, not over Bob's choice of strategy. My point is that he has not demonstrated that 13 or fewer will not do except by getting lucky.

Varsha Dani - 2 years, 7 months ago

Im sorry, I dont know why I read Bob as Brian😂

Parth Sankhe - 2 years, 7 months ago

i don't know, i just using the computer science method of binary search to find the answers. find the median (5000), then divide the remains with N times until the the last remain is equal or lesser to 1, answers are 14 because the last remain is 0.687( less than 1) in the 14th times.

Edwin Gray
Nov 8, 2018

If the response is smaller or larger, he responds again. Since 2^14 > 10,000, but 2^13 < 10,000, the answer must be 14. Ed Gray

1 pending report

Vote up reports you agree with

×

Problem Loading...

Note Loading...

Set Loading...