Frankie and Johnny play the following game. Frankie selects a number at random from the interval $[a, b]$. Johnny, not knowing Frankie’s number, is to pick a second number from that same inverval and pay Frankie an amount, W, equal to the squared difference between the two
[so $0 ≤ W ≤ (b − a)^2]$. What should be Johnny’s strategy if he wants to minimize his expected loss?
Attempt: Let $Y$ be Frankie's choice. Then Johnny wants to choose $k$ so that $E(Y - k)^2$ is minimize.
Can someone please help me? I am having trouble. The answer is Johnny should pick $(a+b)/2$ to minimize his loss.
Unless you know something about Frankie's bias in picking numbers, you have to assume a discrete uniform distribution, which has a probability mass function of $p_Y(h)=1/(b-a+1)$ on the support $h\in\{a..b\}$.
So the expectation is: $$\begin{align} \mathsf E[(Y-k)^2] & = \sum_{h=a}^b (h-k)^2/(b-a+1) & : & h\in\{a..b\}, k\in\{a..b\} \end{align}$$
As you noted in the comments, the minima $k$ is the value that sets the differential to zero. (Rather, your answer will be the nearest integer value.)
$$\begin{align} 0 & = \frac{\mathrm d\;}{\mathrm d k}\mathsf E[(Y-k)^2] \\ & = \frac{\mathrm d\;}{\mathrm d k}\sum_{h=a}^b (h-k)^2/(b-a+1) & : & k\in\{a..b\} \end{align}$$
Note This is assuming Frankie is only allowed to pick integers. Though you get the same result for a continuous uniform distribution, $f_Y(y)=1/(b-a)$.
$$\begin{align} 0 & = \frac{\mathrm d\;}{\mathrm d x}\mathsf E[(Y-x)^2] \\ & = \frac{\mathrm d\;}{\mathrm d x}\int_{a}^b (y-x)^2/(b-a) \operatorname d y & : & x\in[a..b] \end{align}$$