We will play a game. I will pick an integer between $1$ and $100$. Then you will generate a random integer between $1$ and $100$, and you will use it as your number. Whoever has the largest integer must pay the smaller number (i.e. the other player's number) to the other person. What's the best integer for me to pick if I am aware that your numbers are randomly generated?
Let $Z$ be the amount I gain. I tried computing $\mathbb{E}[Z]$ by conditioning and then trying to maximize that equation. Let $x$ be my choice, and let $Y$ be the randomly generated number (I am keeping $x$ lowercase to emphasize that it is not a random variable).
$$E(Z) = E(Z \mid x > Y)P(x > Y) + E(Z \mid x < Y)P(x < Y).$$
First I computed note $P(x > Y) = (x - 1)/100$. Also, $P(x < Y) = (100-x)/100$.
Then I tried to compute $E(Z \mid x > Y)$. Since the player's number is larger than the randomly generated number, they need to pay the randomly generated number to the other player. Since $x > Y$, the expected amount they need to pay is $(x + 1)/2$. Thus,
$$E(Z\mid x > Y)P(x > Y) = \frac{x - 1}{100} \cdot \left(-\frac{x}{2}\right) $$
Next, I compute $E(Z \mid x < Y)$. In this case, the player's number is smaller than the randomly generated number, so they gain $x$. Thus,
$$E(Z \mid x < Y)P(x < Y) = \frac{100 - x}{100} \cdot \left(x\right). $$
So,
$$E(Z) = \left(\frac{1 - x}{100}\right)\left(\frac{x + 1}{2}\right) + \left(\frac{100x - x^2}{100}\right) $$
$$= \frac{-3x^2 + 200x + 1}{200}.$$
This quantity is maximized when $-3x^2 + 200x + 1$ is maximized. The derivative is $200 - 6x$, which implies the maximum occurs at $x = 100/3$.
So I should always bet on $33$ (or should it be $34$)?
My questions:
Is my calculation correct? If so, do I bet on $33$ or $34$? If not, how do I correctly calculate this?
Is there an easier way to do this?
What happens if we add a third person (the second person's number is still randomly generated. the person biggest number has to pay the other two people the number that each one they said)? We suppose that the third player is playing optimally.
Your calculations are mostly correct. The expected amount the other player pays when $x>Y$ is $x/2$ rather than $(x+1)/2$, however: i.e., the average over 1 through $x-1$. Thus $E(Z)$ is $(-3x^2 + 201x)/200$. Your derivation cuts to the essence of the matter -- I don't think there's really a simpler way.
There is something important to note, however, though it may seem like nitpicking. Calculus shows that this function is maximized over the real numbers when $x = 33.5$, whereas you want its maximum over the integers 1 through 100. Rather than rounding this to the nearest integer and hoping it's correct, you can argue as follows. The function's derivative is positive for $x < 33.5$ and negative for $x > 33.5$. Therefore it is strictly increasing in the first region and strictly decreasing in the second. From this it follows that the only candidates for maxima (over the integers 1 through 100) are 33 and 34. You can simply plug them into the equation to check which yields a larger value. Of course, in this case we know that a parabola is symmetric about its maximum, so we may conclude that the value is the same at 33 and 34.