Let's say there are three random numbers in the interval $[0,1]$ (i.i.d. from the uniform distribution).
We do not know what the numbers are. We are shown one of the numbers and our goal is to determine if this shown number is the smallest, largest, or the one in the middle.
What is the best strategy that maximizes our probability of success?
First though: if the number is less than 1/3, say it is the smallest. If it is between 1/3 and 2/3, say it is the middle one. Otherwise, say it is the largest one.
Second thought: Generalize the first thought and find the optimal "pivot". that is, if the number is less than x, say it is the smallest. If it is between x and 1-x, say it is the middle one. Otherwise, say it is the largest one. Compute the probability of success as a function of x. Find the global maximum for x values in $[0,1/2]$.
My attempt for the 'Second thought': I computed that the probability of success is given by the following $$p(x) = \frac{1}{2} (2-x)^2 x + \frac{1}{2}(1-2x)$$ and I concluded that the maximum is attained at $x = \frac{4-\sqrt{10}}{3}$.
However, I was running a simulation and it seems that the pivot x=1/3 gives the best success rate. I am confused. Can anyone help me?
Here is the simulation code (you can change the value of pivot to see what happens):
import numpy as np
import random
import math
def sim():
a1 = random.uniform(0,1)
a2 = random.uniform(0,1)
a3 = random.uniform(0,1)
pivot = 0.33
solution = 0
if a1 < a2 and a1 < a3:
solution = -1
elif a1 > a2 and a1 > a3:
solution = 1
else:
solution = 0
my_guess = 0
if a1 < pivot:
my_guess = -1
elif pivot < a1 and a1 < (1-pivot):
my_guess = 0
else:
my_guess = 1
return int(solution==my_guess)
wins = [sim() for x in range(10**7)]
print(f"Avg wins: {np.mean(wins)}")
```
You don't state in the question whether the number you're shown is chosen at random from the three values (though the title suggests it is). In any case, we can calculate the probability of success given that you're shown each of the three values (lowest, middle, or highest).
If you're shown the lowest value, then you succeed if the lowest value is $< x$. The probability of this is $$ \begin{eqnarray} P_1 &=& 6\int_{0}^{x}dy_1\int_{y_1}^{1}dy_2\int_{y_2}^1dy_3 \\ &=& 6\int_{0}^{x}dy_1\int_{y_1}^{1}dy_2(1-y_2) \\ &=& 6\int_{0}^{x}dy_1\left(y_2-\frac{1}{2}y_2^2\right)\Bigg\vert_{y_1}^{1} \\ &=& 6\int_{0}^{x}dy_1\left(\frac{1}{2}-y_1+\frac{1}{2}y_1^2\right) \\ &=& 6\cdot\left(\frac{1}{2}x-\frac{1}{2}x^2+\frac{1}{6}x^3\right) \\ &=& 3x-3x^2+x^3. \end{eqnarray} $$ Of course the result will be the same if you're shown the highest value ($P_3=P_1$). Finally, if you're shown the middle value, then you fail if the middle value is less than $x$ or greater than $1-x$. The probability of the first of these is $$ \begin{eqnarray} Q &=& 6\int_{0}^{x}dy_1\int_{y_1}^{x} dy_2 \int_{y_2}^{1} dy_3 \\ &=& 6\int_{0}^{x}dy_1 \int_{y_1}^{x} dy_2(1-y_2) \\ &=& 6\int_{0}^{x}dy_1\left(y_2-\frac{1}{2}y_2^2\right)\Bigg\vert_{y_1}^{x} \\ &=& 6\int_{0}^{x}dy_1\left(x-\frac{1}{2}x^2-y_1+\frac{1}{2}y_1^2\right) \\ &=& 6 \cdot \left(x^2-\frac{1}{2}x^3-\frac{1}{2}x^2+\frac{1}{6}x^3\right) \\ &=& 3x^2-2x^3 \end{eqnarray} $$ The second is the same by symmetry, and so $P_2=1-2Q=1-6x^2+4x^3$. Putting everything together, and now assuming that the revealed number is chosen at random from the three, your final probability of success is $$ \begin{eqnarray} P &=& \frac{1}{3}(P_1+P_2+P_3) \\ &=& \frac{2}{3}P_1+\frac{1}{3}P_2 \\ &=& \left(2x-2x^2+\frac{2}{3}x^3\right) + \left(\frac{1}{3}-2x^2+\frac{4}{3}x^3\right) \\ &=& \frac{1}{3}+2x-4x^2+2x^3. \end{eqnarray} $$ And indeed this is maximized at $x=1/3$, where it takes the value $P_{\max}=17/27$.