An Unintuitive Coin Flip Problem (With Secret Markov Chains)
Professor Peter
0:00 / 0:00
An Unintuitive Coin Flip Problem (With Secret Markov Chains)
13 829 просмотров · 6 лет назад
Professor Peter
1,17 тыс. подписчиков
13 829 просмотров · 6 лет назад
Here's a seemingly easy coin flip probability question that might have you reconsidering what you know about probabilities. Under the surface of this short problem is a probability phenomena known as a Markov Chain. In this video we'll introduce the problem, try to simulate it using some python code, and then explain why the results we're seeing seem to contradict what we know about probability and coin flips.
---------------
I tweet math things on Twitter: / mathprofpeter
I stream math things on Twitch: / professorpeter
---------------
Python code (in case you want to try it yourself):
import random
###################################
Setup
###################################
population = [0,1] # 0 = H, 1 = T
pattern1 = [0,0,1] # HHT
pattern2 = [0,1,1] # HTT
trials = 1000000 # a million trials!
p1wins = 0
p2wins = 0
###################################
Flip the coins and check the patterns we see
###################################
for x in range(0,trials):
fliplist = []
while fliplist != pattern1 and fliplist != pattern2:
Flip a coin, add it to the list, check against the patterns
flip = random.choice(population)
fliplist.append(flip)
fliplist = fliplist[-3:] # only keep the latest 3 flips
if fliplist == pattern1:
p1wins = p1wins + 1
if fliplist == pattern2:
p2wins = p2wins + 1
###################################
Summary information
###################################
p1percent = round(float(p1wins)/trials * 100,2)
p2percent = round(float(p2wins)/trials * 100,2)
print "Pattern 1 (HHT) won", p1wins, "times. This is ", p1percent, "%"
print "Pattern 2 (HTT) won", p2wins, "times. This is ", p2percent, "%"