Dependent Coinflip Calculation

85 Views Asked by At

If I have a coin that's fair on the first flip, but after getting a heads it has a 90% chance of getting heads on the following flip, what are the odds of the coin being heads on any random trial? Assume after getting tails the probability resets to fair.

I wrote some python code that tells me it's around 91%, but I'm not sure how to calculate this:

heads_counter = 0
iterations = 0

while iterations < 1000000:
    if random.random() > .5:
        heads_counter += 1
        iterations += 1
        heads = True
        while heads:
            if random.random() > .1:
                heads_counter += 1
                iterations += 1
            else:
                heads = False
                simulations += 1
    else:
        iterations += 1

heads_counter / (1. * iterations)
1

There are 1 best solutions below

1
On BEST ANSWER

If you are looking for the stable long-term distribution, you have:

  • $P(H)=\dfrac9{10}P(H)+\dfrac12P(T)$
  • $P(T)=\dfrac1{10}P(H)+\dfrac12P(T)$
  • $P(H)+P(T)=1$

The first two each give $P(H)=5P(T)$, which combined with the third gives

  • $P(H)=\dfrac56$
  • $P(T)=\dfrac16$