Optimal Strategy Question Someone asked me this question a while ago and I'm not sure how to go about it: 

Suppose two players are playing a game. The first player  chose an
  integer between 1-30. The second player picks a different one. After
  that, a random integer (x) between 1-30 will be generated with uniform distribution. The player
  whose number is closer to x gets paid x dollars. What number should you pick if you go first?

My gut tells me it's 15 but since there is more weighting on the payoff for larger values it should be larger than that. Apparently the optimal strategy is to choose 22. What is the best way to approach this question?
 A: The first question is: what do we mean by "should" in "what number should we pick"? The best strategy depends on what the other player will do. I'll assume that the second player is self-interested and rational, so they'll always pick the strategy which gives them the best outcome. I'll also assume that what we care about here is average gain, so "best" means maximizing expected profit.
If the first player chooses $a$ and the second player chooses $b$, then their expected profits are determined and we can calculate them. For each $a$ there then exists a $b$ which maximizes player two's profit, and we can compute player one's profit given those choices. We then choose the $a$ that maximizes that value.
The full calculation is a little tedious and I don't feel like working out the fine print right now. I did a sketch of it below and got the wrong answer ($21$ rather than $22$), but it illustrates the process and shows where the number $22$ comes from.

So for the choices $a$, $b$, the expected profits are roughly:
$$\frac{N+\frac{b+a}2}2\frac{N-\frac{b+a}2}N=\frac{N^2-m^2}{2N}$$
for whoever picks the highest number, and
$$\frac{\frac{b+a}2}2\frac{\frac{b+a}2}N=\frac{m^2}{2N}$$
for whoever picks the lowest number, where $N=30$ and $m=\frac{b+a}2$.
So suppose we pick $a$. From the above formulae you can see that your opponent's best move is going to be to pick either $a+1$ or $a-1$, depending on which one gives them the most profit. Working out the inequality, we'll obtain that $a+1$ is the superior choice precisely when $a^2\leq\frac{N^2-\frac12}2$, that is when $a\leq21.2$.
By the same logic which shows that player two's best bet is to pick either $a+1$ or $a-1$, we can immediately conclude that our best first move is to pick either $21$ or $22$. In either case we will have $m=21.5$. When we work out which of the two possibilities gives us the higher expected profit, we actually get $21$, not $22$.
A: The best way to approach this, is to calculate the expected profit after the event $x$ has occured.
An intuitive explantation why 22 is the optimal strategy goes as follows. Say you play this game a lot of times ($n$), and you always choose 22. If the other player chooses a number lower than yours, say 21, he will win when the number is lower than 22. You will win if the number is 22 or higher. If all numbers are rolled equally often you will profit $\frac{n}{30} (22 + \cdots + 30) = n\frac{234}{30}$. He will win $\frac{n}{30} (1 + 2 + \cdots + 21) = n\frac{231}{30}$. If he chooses a number larger than you then you will win 22 or lower, which by a similar calculation shows that you will win more than you lose.
