One day, you decide to play a game with your friend out of sheer boredom. Your friend picks out an integer randomly from the range [ 1 , 1 0 2 3 ] and you try to guess it.
You can guess an infinite number of times. Let n denote the integer your friend chose and let k i denote the integer you chose on the i th try. If n > k i your friend will tell you "higher", if n < k i your friend will tell you "lower" and if n = k i then you win the game.
But then, your friend decides this is too boring. He decides to give you 1023 dollars. Every time you make a guess, right or wrong you have to give him x dollars, even if you already gave him back the original 1023 dollars or even if you already have negative profits. Since your friend knows that you will play optimally, he sets x such that your expected profit after playing the game is 0. Find ⌊ x ⌋ .
Notation : ⌊ ⋅ ⌋ denotes the floor function .
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.
(+1)...did the same... I actually found the hidden message(..yet again :-p)
Log in to reply
Grrr.... what gave it away this time?
Log in to reply
Now it's kind of a habit to Toggle Latex whenever I see your problem.... But obviously that blank space gives an idea.. :-)
Log in to reply
@Rishabh Jain – Grr...
Speaking of which, where did comrade otto go?
Log in to reply
@Manuel Kahayon – Summoning @Otto Bretscher
Log in to reply
@Pi Han Goh – Ahahaha some sort of summoning spell :)
@Manuel Kahayon – Obviously he would be back apart from wherever he has gone .... So keep Calm and wait for him XD
Can you explain why "We know that the optimal algorithm for playing this game is choosing the median of the numbers first"? To me, that is the main part of the argument, which you are sweeping under the rug. The rest of the calculation can be boringly calculated.
Log in to reply
Assume that we do not take the median of the numbers. This implies that there are more numbers higher than the chosen number than the number of numbers lower than the chosen number or vice versa. If there are more higher numbers, then if our friend says higher then we would require more steps in order to pinpoint the number. Or something like that.
Log in to reply
Yes, I understand that is the intuition behind the reason. However, it should be formulated more rigorously, for us to understand why. For example, why doesn't it matter that "if we're in the case with fewer numbers, we then need fewer guesses"? How are we so sure that this benefit is outweighed by the loss?
I agree that in the extreme case (where we guess 1), that is clearly disadvantageous. Is this disadvantage a strictly increasing function as we move away from guessing the median? Why, or why not?
Log in to reply
@Calvin Lin – Hmm. I'm gonna think of a solution for this one. Never realized that I cast aside such a huge question for this problem. But, sorry, I need to go to school first. I'm thinking recurrence relations. Am I on the right track?
@Calvin Lin – AAAAAH, I got it!!!
We have to represent all of the numbers from 1 to 1023 by a unique "higher-or-lower" number system. For example, if we always choose the second lowest number in the list of possible numbers, our number system for 7 would go like this
"(chose 2) Higher-(chose 4)Higher-(Chose 6) Higher-(Chose 8) lower"
Now, this can be represented as
" H H H L "
Now, we can easily see that this is extremely similar to a binary number. Since 1 0 2 3 = 1 1 1 1 1 1 1 1 1 2 , then to map all of the integers from 1 to 1023 in this system would require at least 9 highers and lowers, which is done by the algorithm given. So, the algorithm is optimal. XD
@Calvin Lin – And, this suffices to prove that the expected value is the same no matter what algorithm is usef as long as it is optimal. The binary structure of highers and lowers ensures that every time you get a 1 0 2 3 2 n chance of getting it right on the xth try
Its just like finding an element in a sorted array ranging from 1 to 1023 through binary search. If i had to guess a no. Between 1 and 1023, i would choose 512 which is the center of the range and procede as per my friend's response which is nothing but binary search.
We know, complexity of binary search is (log n) so (log 1023) = 9.99 I.e. Atleast 9 chances are needed for correct guess.
To balance the money to 0, 1023 = 9x , where x is the amount set. => x = ceil(1023/9) = ceil(113.66) = 113
I disagree that "at least 9 chances are needed". Sometimes, you can find the answer in one guess. Sometimes in five. Most often it will take 10 turns.
So it takes a little more effort than you did to show, that the expected number of guesses is 9 2 1 7 / 1 0 2 3 ≈ 9 . 0 0 9 8 .
Essentially you were lucky to arrive at the correct answer, because 9 . 0 0 9 8 … is so close to the number 9 you picked.
Why must we use a binary search? How do you know that it would minimize the expected number of searches?
Log in to reply
Because, for each guess we throw out the greatest amount possible of wrong answers, which is half of the total left. Guessing at random may get you a lower amount of probabilities left, but most likely you will eliminate less than half of the total, so binary is the quickest overall method.
Log in to reply
Yes, I agree that is the intuitive understanding. What is the rigorous explanation/proof of that fact?
Log in to reply
@Calvin Lin – https://grid.cs.gsu.edu/~cscskp/Algorithms/search/node11.html
My friend knows that i will play optimally, so if on every guess I choose a no. Other than the mid value, I will either have <n/2 or >n/2 options which could be the worst case or the best case for that guess but not the optimal case.
I have a problem with this solution of 113. The actual steps taken, in a binary search from 1 to 1023 to get to 113 do not add up to 1023. In the order of the guesses the steps are: 1 - 512 2 - 256 3 - 128 4 - 64 5 - 96 6 - 112 7 - 120 8 - 116 9 - 114 10 - 113
When I add all these up I get 1631 dollars, meaning I lost 607 dollars.
My friend knows I will play optimally (binary search) and unless I understand 0 profit in a very weird way, it would also imply 0 loss.
If the answer was 1, the binary search steps would add up to 1023 exactly, so 0 profit and 0 loss.
Problem Loading...
Note Loading...
Set Loading...
Relevant wiki: Expected Value - Problem Solving
Veeery long solution.
First off, we notice that 1 0 2 3 = 2 1 0 − 1 , so now what? We know that the optimal algorithm for playing this game is choosing the median of the 1 0 2 3 numbers first, i.e. 5 1 2 . Our friend tells us either lower or higher or correct, so in the first two cases we can eliminate 5 1 2 of the numbers as possible candidates leaving us with 5 1 1 remaining candidates. Notice that if we repeat this step again and again, we can see that every time we remove numbers from the possible candidates, the remaining numbers always have a median, or in other terms, the number of possible candidates is always odd.
Now, we have to calculate the expected value for the number of trials it will take us before we actually get the number our friend wants us to fin, following the algorithm. We know that there is a 1 0 2 3 1 probability that we get it right on our first try. But how about on the second try?
On the second try we will either choose 2 5 6 or 7 6 8 depending on the circumstances. So, if the number were to be one of these, we would get it right immediately on our second try. So, the expected number of moves for this case is 2 ( 1 0 2 3 2 ) = 1 0 2 3 4 .
How about on our third try? Using the same logic above, if the number were to be 1 2 8 , 3 8 4 , 6 4 0 , 8 9 6 , we would get it immediately on our third try. Now for this case the expected value is 3 ( 1 0 2 3 4 ) = 1 0 2 3 1 2 .
Notice anything yet? The probability of getting the number right on the n t h term is 1 0 2 3 2 n − 1 , so for any given case the expected value is 1 0 2 3 n 2 n − 1 . The expected value then becomes
n = 1 ∑ 1 0 1 0 2 3 n 2 n − 1 = ( n = 1 ∑ 1 0 n 2 n − 1 ) 1 0 2 3 1 .
Now, this is an arithmetic-geometric progression . We evaluate it to be 1 0 2 3 9 2 1 7 by the formula given on the page. Now, since x ∗ E = 1 0 2 3 where E is the expected value (calculated from the given), we have
1 0 2 3 9 2 1 7 x = 1 0 2 3
Giving us x = 9 2 1 7 1 0 2 3 2 = 1 1 3 . 5 4 . Therefore our answer is
⌊ x ⌋ = ⌊ 1 1 3 . 5 4 ⌋ = 1 1 3 .