(Disclaimer: This is not a homework question). I am trying to teach my self some elementary probability, and I thought of this following example: Imagine you are playing a game involving two coins. In order to win the game you must flip heads before your opponent. That is, if they flip heads first they win and you lose. Let's also assume the game is played in a turn based fashion and you are flipping the coin first. Also, the coins are 'unfair' with $P(X=heads)|_{coin 1}=p_1$ and $P(X=heads)|_{coin 2} = p_2$.
I am unsure how to compute on average how many turns it will take to win the game.
So far, I believe we can model this game with the following function $P(X=k) = p_1(1-p_1)^{k-1}(1-p_2)^{k-1}$ (which appears very similiar to a geometric distribution), because in order to win the game (assuming you flipped tails first) the opponent must flip tails with probability $(1-p_2)$ or you lose. This pattern repeats for each round of the game.
I believe the probability of winning is equal to $\sum_{k=1}^{\inf}p_1(1-p_1)^{k-1}(1-p_2)^{k-1}$ and the expected number of turns to win is given by $\sum_{k=1}^{\inf}p_1(1-p_1)^{k-1}(1-p_2)^{k-1} k$.
I wrote a Monte Carlo simulation to compute these values with the assumption of values for $p_1$ and $p_2$, but that is not satisfactory for me. I would like to know how to solve this problem mathematically as opposed to programmatically.
Two questions: 1) Am I on the right track with the probability of winning and the expected number of turns to win? 2) If so, can you assist me in solving these infinite series. Admittedly, I am not great with solving series.
Edit: The question has been answered, but I wanted to post my code in case anyone is interested. (I was originally thinking about this problem in terms of a naval battle, so that's why the comments and variable names are named that way).
from pylab import *
nSim = 100000
p_h1 = 0.5
p_h2 = 0.5
number_won = 0
total_shots = []
for i in range(nSim):
won = False
shots_fired = 0
while not won:
shots_fired += 1
# simulate shot
shot = rand(1)
# if it hits, the game is over
if shot <= p_h1:
won = True
number_won += 1
# else, other player shoots
else:
shot = rand(1)
if shot <= p_h2:
won = True
total_shots.append(shots_fired)
print 'from monte carlo simulation:'
print 'P(win): ', float(number_won) / float(nSim)
print 'expected # of shots: ', np.array(total_shots).mean()
# testing
print 'from theory:'
denom = (1-p_h1)*(1-p_h2)
print 'P(win): ', p_h1 / (1 - denom)
pstar = (1 - (1-p_h1)*(1-p_h2))
print 'expected # of shots: ', 1. / pstar
and the output:
from monte carlo simulation:
P(win): 0.66706
expected # of shots: 1.33967131236
from theory:
P(win): 0.666666666667
expected # of shots: 1.33333333333