Monty Hall Problem
2013-03-14 20:46
225 查看
import sys
import random as rnd
#strategy=sys.argv[1]# must be 'stick','choose',or 'switch'
def Solve(strategy):
wins = 0
for trail in range(100):
#The price is always in envelop 0... but we don't know that!
envelopes = [0,1,2]
first_chose = rnd.choice(envelopes)
if first_chose == 0:
envelopes = [0,rnd.choice([1,2])] #Randomly retain 1 or 2
else:
envelopes=[0,first_chose]# Retain winner and first choice
if strategy == 'stick':
second_choice = first_chose
elif strategy == 'choose':
second_choice= rnd.choice(envelopes)
elif strategy == 'switch':
envelopes.remove(first_chose)
second_choice = envelopes[0]
if second_choice ==0:
wins += 1
print strategy +':' + str( wins)
Solve('stick')
Solve('choose')
Solve('switch')
import random as rnd
#strategy=sys.argv[1]# must be 'stick','choose',or 'switch'
def Solve(strategy):
wins = 0
for trail in range(100):
#The price is always in envelop 0... but we don't know that!
envelopes = [0,1,2]
first_chose = rnd.choice(envelopes)
if first_chose == 0:
envelopes = [0,rnd.choice([1,2])] #Randomly retain 1 or 2
else:
envelopes=[0,first_chose]# Retain winner and first choice
if strategy == 'stick':
second_choice = first_chose
elif strategy == 'choose':
second_choice= rnd.choice(envelopes)
elif strategy == 'switch':
envelopes.remove(first_chose)
second_choice = envelopes[0]
if second_choice ==0:
wins += 1
print strategy +':' + str( wins)
Solve('stick')
Solve('choose')
Solve('switch')
相关文章推荐
- ZZULIOJ 1721 Monty Hall problem
- The Monty Hall Problem-蒙特霍问题
- 概率 三门问题 Monty_Hall_problem
- Monty Hall problem 【三门问题 】
- Monty Hall Problem的一个图解,感觉不错
- 確率・統計特論笔记(1) Monty Hall Problem&Bertrand paradox
- 羊和汽车问题(或s三门问题(Monty Hall problem)亦称为蒙提霍尔问题)
- 三门问题(Monty Hall problem)简析
- 有趣的三扇门问题(Monty Hall Problem)
- zzulioj--1712--Monty Hall problem(蒙提霍尔问题)
- BNUOJ 44578 Monty Hall problem
- sql server:Monty Hall problem (蒙提霍尔问题)
- Monty Hall Problem
- zzulioj--1712--Monty Hall problem(蒙提霍尔问题)
- The Monty Hall Problem
- Monty Hall问题 模拟
- 追溯羊与车:Monty Hall Dilemma问题的故事
- {分享}《Matrix67:信息学竞赛中可能有用的概率学知识》——Monty Hall问题
- Google Code Jam 2012 Qualification Round. Problem D. Hall of Mirrors
- Harvard statistics, video 6 note(Monty Hall & Simpson's paradox)