# Optimal guess in a game

Suppose that A and B play a strange game. At the beginning of the game A can choose one real number - $$x$$ - between $$0$$ and $$60$$. Each round of the game goes like this:

1. B names random real number $$b$$ between $$0$$ and $$60$$ with uniform probability.

2. If $$b > x$$ then A pays $$3(b - x)$$ dollars. If $$b <= x$$ then A pays $$x - b$$ dollars.

How should A choose $$x$$ so that the expected payment is minimal?

Consider that for a guess from A of $$x$$ that, over time, they expect to pay out the area of the graph:

$$\int_0^x (x-b) db + \int_x^{60} 3(b-x) db$$

Note that when $$b=x$$ then the payout is zero in both integrals, and so we do not need to worry about what happens here.

The integrals evaluate to:

$$\left(xb-\frac{b^2}{2}\right)\mid_0^x + \left(\frac{3b^2}{2}-3xb\right)\mid_x^{60}$$
$$=(x^2-\frac{x^2}{2}-0 + 0)+(5400-180x-\frac{3x^2}{2}+3x^2)$$
$$=2x^2-180x+5400$$

To optimize A's choice of $$x$$, we need to minimize this function, and so we take the differential:

$$\frac{d}{dx}=4x-180$$

and set to zero to find

$$x=45$$

45
Think marginal risk.
Consider that B is chosing $$b' = (b-x)$$. The value $$b'$$ is then chosen uniformly between $$-x$$ and $$60-x$$. The payout is $$3 b'$$ if $$b>0$$, or $$-b'$$ if $$b'<0$$.
If A moves $$x$$ by a small amount, then the payout is the same everywhere, it only changes by moving the range of $$b'$$. When increasing $$x$$ a little bit, A adds a risk of a $$3b' = 3(60-x)$$ payout near the high end and avoids a risk of a $$-b' = +x$$ payout near the lower end.
A should therefore increase $$x$$ if $$x < 3(60-x)$$ i.e. if $$x < 45$$. A should lower $$x$$ if $$x>45$$. In short, the best is $$x = 45$$.