You and I decide to play a game where we take turns flipping a coin. The first player to flip 10 heads in total wins the game. Naturally, there is an argument about who should go first.
Simulations of this game show that the player to flips first wins 6% more than the player who flips second (the first player wins approx 53% of the time). I'm interested in modelling this analytically.
This isn't a binomial random variable, as there are no fixed number of trials (flip until someone gets 10 heads). How can I model this? Is it the negative binomial distribution?
So as to be able to recreate my results, here is my python code:
import numpy as np
from numba import jit
@jit
def sim(N):
P1_wins = 0
P2_wins = 0
for i in range(N):
P1_heads = 0
P2_heads = 0
while True:
P1_heads += np.random.randint(0,2)
if P1_heads == 10:
P1_wins+=1
break
P2_heads+= np.random.randint(0,2)
if P2_heads==10:
P2_wins+=1
break
return P1_wins/N, P2_wins/N
a,b = sim(1000000)