I have been learning python programming on edX which is a very good course and I can so far fully recommend. Having just watched a TED talk on Statistics I thought great, a simple way of exercising the python skills I have picked up on a real world scenario. The guy gave an example on probability of continually flipping a coin and looking out for two recurring sequences, which he explained, you would think had the same probability of happening which he claimed in fact don't. Put simply he claims the sequence Heads Tails Heads is more likely to occur than Heads Tails Tails as at the end of the first sequence you are are already one third towards repeating the sequence again where at the end of the second sequence you then have to toss a further head to begin the sequence again. This makes perfect sense, so I set about trying to prove it with my small python program shown here.
import random
HTH = 0
HTT = 0
myList = []
i = 0
numberOfTosses = 1000000
while i < numberOfTosses:
myList.append(random.randint(0,1))
i += 1
for i in range (len(myList)):
if i+2 >= len(myList):
break
if myList[i] == 1 and myList[i+1] == 0 and myList[i+2] == 1:
HTH +=1
if myList[i] == 1 and myList[i+1] == 0 and myList[i+2] == 0:
HTT +=1
print 'HTT :' ,numberOfTosses, HTT, numberOfTosses/HTT
print 'HTH :' ,numberOfTosses, HTH, numberOfTosses/HTH
So I have run the program many times and changed the max iteration value higher and higher, yet cannot seem to prove his claim that on average the HTH sequence should happen evey 8 tosses and the HTT sequence every 10, as it would seem that I get on average balanced results either way. So my question is where have I gone wrong in my implementation of the problem?