You play a number guessing game in which you must pick a real number x, between 0 and 924. At the same time, the number y is uniformly and randomly selected from the same range. If x is greater than y, then you have to pay the square of the difference between the two numbers. If y is greater than or equal to x, you pay double the difference. What number should you choose initially?
Solution:
When faced with a number guessing game, you should start by looking at the cost function and the changes that happen when you vary your choice of x. For a fixed value of x, the expected cost is proportional to the sum of areas under the two curves.
Just as we expect, the quadratic side is increasing much faster than the linear one when the value of x increases.
Let f(a)=a2, g(a)=2⋅a,(∀a∈R) and let Z be the cost of this game. We want to minimize E=∫0xf(x−y)9241dy+∫x924g(y−x)9241dy
To simplify the above formula of the expectation we use a change of variable, which leads us to the simplified problem of minimizing:
h(x)=−F(0)−G(0)+F(x)+G(924−x)
Where F and G are the primitives of f and g respectively
Derivating the above formula we find a suitable candidate for a minimum: x0=42, and check that indeed it minimizes our expected loss:
One other solution would be to find the optimal solution using python: