Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Monty problem
1.
2. Monty Problem
Problem originated from show
“Lets make a deal”*
3 doors, 1 contains a price
($1000)
Price place at random
Ex: D1
Player picks a door
Ex: D1
Host opens a door that
doesn’t have the price
Ex: D3
Should player switch to the
other door?
*https://en.wikipedia.org/wiki/Monty_Hall_problem
D1 D2 D3
D1 or D2 ?
4. Simulating Monty Problem
in Python
Price placed at
random in one of 3
doors
1000 trials run
Each door has
probability 1/3 of
having the price
Each door has
price ~333 times
np.random.seed()
doorPr = int(np.floor(np.random.uniform(1, 4))) # door where price is
doorPrice.append(doorPr)
5. Simulating Monty Problem
in Python
Player 1 picks door at
random and never switches
to the other door
Player 2 also picks door at
random but always switches
to the other door after host
shows empty door
Who is more likely to win?
10. Python Code
for t in range(trials):
np.random.seed()
doorPr = int(np.floor(np.random.uniform(1, 4))) # door where price is
doorPrice.append(doorPr)
# player 1
doorP1 = int(np.floor(np.random.uniform(1, 4))) # door for player 1
doorPlayer1.append(doorP1)
doorList = [doorPr, doorP1]
doorDict = {'d1':0,'d2':0,'d3':0}
11. Python Code
for door in doorList:
key = 'd' + str(door)
doorDict[key]+=1 # Add 1 to value in dictionary
# whenever a door is chosen
other2 = switchDoor2(doorDict) # host opens door different
from
# door with prize and chosen by player 1
12. Python Code
# player 2
doorP2 = int(np.floor(np.random.uniform(1, 4)))
doorPlayer2.append(doorP2)
doorList = [doorPr, doorP2]
doorDict = {'d1': 0, 'd2': 0, 'd3': 0}
for door in doorList:
key = 'd' + str(door)
doorDict[key] += 1
13. Python Code
other3 = switchDoor2(doorDict)
key = 'd'+str(other3)
del doorDict[key] # door no longer available since it was open
for key in doorDict.keys():
keyP2 = 'd' + str(doorP2)
if keyP2 != key:
switch = int(key[1])
doorOther3.append(other3)
doorPlayer2b.append(switch)