In [1]:
from __future__ import division
from tqdm import *
import numpy as np
import scipy.stats as st
In [2]:
def round(index):
i = 0
odd_previous_heads = False
while(True):
# 0 = heads, 1=tails
elem = np.random.choice([0,1])
i += 1
if(elem == 0):
if(odd_previous_heads == True):
odd_previous_heads = False
else:
odd_previous_heads = True
else:
if(odd_previous_heads == True):
return i
else:
continue
In [3]:
num_rounds = []
for i in trange(1,1000000):
num_rounds.append(round(i))
print(np.mean(np.array(num_rounds)))