A and B are playing a game.
Player A asks B to choose a number from 1 to 100,000 and keep it as a secret.
Player A has to guess the secret number. Player A will get as many tries as he wants. But the rule is that whenever player A guesses a number (let that no. be x), Player B will tell him if x is greater than or less than the secret number.
How many tries does A need to surely guess the secret number?
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.
In the whole solution i've assumed that A will not get the correct answer without guessing the required number of times. Let's assume that A's first guess is p 1 . Then the chances of p 1 being less than the answer is 1 0 0 0 0 0 1 0 0 0 0 0 − p 1 and the chances of p being greater than the answer is 1 0 0 0 0 0 p 1 − 1 . Let these two fractions be x 1 and x 2 where x 1 < x 2 . We need two get minimum possible value of x 1 to reduce the number of turns required. By solving we will get, p 1 =50000. So the first guess should be 50000. Now, there will be 2 cases,
In case 1, A's second guess would be p 2 , on solving, gives us 25000. In case 2, A's second guess would be p 2 + p 1
We will repeat this n times, till p n becomes 1 (actually less than 1). We are halving p on every step. By halving 100000 n times, we get a value less than 1. So we get the equation:-
2 n 1 0 0 0 0 0 < 1 1 0 0 0 0 0 < 2 n B y p u t t i n g v a l u e s w e g e t min ( n ) = 1 7