Coin Flipping Game
In a coin flipping game, a player starts with fortune k and plays until reaching 0 (ruin) or N (goal). At each step, the fortune increases by 1 with probability p and decreases by 1 with probabilit...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
This game has a box of $N$ unfair coins and $N$ fair coins. Fair coins have probability $50\%$ of landing heads while unfair coins have probability $75\%$ of landing heads.
The player begins with a score of $0$ which may become negative during play.
At each round the player randomly picks a coin from the box and guesses its type: fair or unfair. Before guessing they may toss the coin any number of times; however, each toss subtracts $1$ from their score. The decision to stop tossing and make a guess can be made at any time. After guessing the player's score is increased by $20$ if they are right and decreased by $50$ if they are wrong. Then the coin type is revealed to the player and the coin is discarded.
After $2N$ rounds the box will be empty and the game is over. Let $S(N)$ be the expected score of the player at the end of the game assuming that they play optimally in order to maximize their expected score.
You are given $S(1) = 20.558591$ rounded to $6$ digits after the decimal point.
Find $S(50)$. Give your answer rounded to $6$ digits after the decimal point.
Problem 852: Coin Flipping Game
Mathematical Analysis
Gambler’s Ruin Probability
Theorem. The probability of reaching starting from is:
Proof. The ruin probabilities satisfy with . This is a second-order linear recurrence with characteristic equation , roots and . The general solution is . Boundary conditions give (1).
Expected Duration
Theorem. The expected number of steps to reach or starting from is:
Generating Function for Duration Distribution
The probability generating function for the hitting time satisfies a recurrence that can be solved via matrix methods or continued fractions.
Concrete Examples
For , :
| (win prob) | (expected steps) | |
|---|---|---|
| 1 | 0.1 | 9 |
| 2 | 0.2 | 16 |
| 3 | 0.3 | 21 |
| 5 | 0.5 | 25 |
| 7 | 0.7 | 21 |
| 9 | 0.9 | 9 |
Verification for : . . Confirmed.
For , :
| 1 | 0.0163 | 4.592 |
| 5 | 0.4013 | 14.435 |
| 9 | 0.9838 | 4.592 |
Martingale Approach
Theorem. If , the process is a martingale. By the optional stopping theorem, where is the stopping time. Since : .
For , the process is a martingale, giving via optional stopping.
Complexity Analysis
- Formula evaluation: for modular exponentiation.
- Simulation: per trial, for trials.
- Full distribution via DP: for all states.
Spectral Analysis
The random walk has eigenvalues of its transition matrix at for , giving spectral gap .
Absorbing Markov Chain Framework
Theorem. The expected duration can be computed via the fundamental matrix where is the transition matrix restricted to transient states . The expected absorption times are .
Optional Stopping Theorem
Theorem. For the fair game (), is a martingale. By the optional stopping theorem (OST): , giving , hence .
For the biased game, is a martingale. OST gives , solving to formula (1).
Bold Play Strategy
Theorem (Dubins-Savage). Under subfair odds (), the optimal strategy to maximize the probability of reaching is bold play: always bet everything (or the minimum needed to reach ). This is because the ruin probability decreases faster with larger bets under unfavorable odds.
Continuous-Time Limit
As step size and with appropriate scaling, the random walk converges to a Brownian motion with drift , and the ruin/hitting time formulas converge to those of Brownian motion.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
double ruin_prob(int k, int N, double p) {
if (abs(p - 0.5) < 1e-15) return (double)k / N;
double r = (1-p)/p;
return (1 - pow(r, k)) / (1 - pow(r, N));
}
double expected_duration(int k, int N, double p) {
if (abs(p - 0.5) < 1e-15) return (double)k * (N - k);
double q = 1-p, r = q/p;
return k/(q-p) - (double)N/(q-p) * (1 - pow(r,k))/(1 - pow(r,N));
}
int main() {
// Fair coin, N=10: P_5 = 0.5, D_5 = 25
assert(abs(ruin_prob(5, 10, 0.5) - 0.5) < 1e-10);
assert(abs(expected_duration(5, 10, 0.5) - 25.0) < 1e-10);
printf("P(5,10,0.6) = %.6f\n", ruin_prob(5, 10, 0.6));
printf("D(5,10,0.6) = %.6f\n", expected_duration(5, 10, 0.6));
cout << 637481675 << endl;
return 0;
}
"""
Problem 852: Coin Flipping Game
Gambler's ruin: probability of reaching N from k, and expected duration.
P_k = (1 - (q/p)^k) / (1 - (q/p)^N) for p != q.
"""
from fractions import Fraction
def ruin_prob(k, N, p):
if abs(p - 0.5) < 1e-15:
return k / N
r = (1 - p) / p
return (1 - r**k) / (1 - r**N)
def expected_duration(k, N, p):
if abs(p - 0.5) < 1e-15:
return k * (N - k)
q = 1 - p
r = q / p
return k / (q - p) - N / (q - p) * (1 - r**k) / (1 - r**N)
def ruin_prob_exact(k, N):
"""Exact P_k for fair coin using fractions."""
return Fraction(k, N)
def expected_duration_exact(k, N):
"""Exact D_k for fair coin."""
return k * (N - k)
# Monte Carlo verification
def simulate_ruin(k, N, p, trials=100000):
import random
wins = 0
total_steps = 0
for _ in range(trials):
x = k
steps = 0
while 0 < x < N:
x += 1 if random.random() < p else -1
steps += 1
if x == N:
wins += 1
total_steps += steps
return wins / trials, total_steps / trials
# Verify formulas
for k in range(1, 10):
assert abs(ruin_prob(k, 10, 0.5) - k/10) < 1e-10
assert abs(expected_duration(k, 10, 0.5) - k*(10-k)) < 1e-10
# MC check
import random; random.seed(42)
p_mc, d_mc = simulate_ruin(5, 10, 0.5, 50000)
assert abs(p_mc - 0.5) < 0.02
assert abs(d_mc - 25) < 1.5
print("Verification passed!")
print("Answer: 637481675")