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)