Main Question:
My game works as follows:
- You start with 1 coin and flip it. When you move to the next round, you add another coin and repeat.
- You move on to the next round if the majority of the coins flipped in the current round come up heads. Otherwise, you lose the game.
I've been trying to calculate the expected value of this game — the average round you get to before you lose.
I've calculated that, for a given round R:
$P(\text{win round R}) = \frac{1}{2^R}\sum^{R}_{k=floor(R/2)+1}{R \choose k}$
and with a simulation in Java, the expected value came out to be about $1.7229533856734633$, but I've no clue of a closed form for this value.
How would I find this expected value, analytically? Thank you!
Simulation Code, if there's discrepancy between the analytic expected value and the simulated one:
public static void main(String[] args) {
int total = 0;
double sim = Math.pow(2.0, 30.0);
for (int i = 0; i < sim; i++) {
total += game();
}
System.out.println((double) total / sim);
}
public static int flip(int coins) {
int heads = 0;
for (int i = 0; i < coins; i++)
{
if (Math.random() >= 0.5)
heads++;
}
return heads;
}
public static int game() {
int coins = 1;
while (flip(coins) > coins/2) {
coins++;
}
return coins;
}