首页 > 其他分享 >三门问题

三门问题

时间:2022-11-01 22:35:24浏览次数:38  
标签:choiceIndex 概率 random 重选 carIndex 问题 三门 total

times = 1000
changeList = []
noChangeList = []

for i in range(times):
    #车真实位置
    carIndex = random.randint(1,3)

    #玩家选择
    choiceIndex = random.randint(1,3)

    #主持人排除(其实对结果计数无影响)
    total = [1,2,3]
    total.remove(carIndex)
    try:
        total.remove(choiceIndex)
    except:
        pass
    removeIndex = random.choice(total)

    #不重选
    noChangeList.append(carIndex==choiceIndex)
    #重选
    changeList.append(carIndex!=choiceIndex)

print(sum(changeList))
print(sum(noChangeList))
  • 一开始选对的概率是1/3,不对的概率是2/3

  • 排除一个错误选项后,无脑重选,则必然是对变错,错变对

  • 则无脑重选后,对的概率是2/3(对应之前不对的概率),不对的概率是1/3(对应之前对的概率)

  • 中间过程对最终决策的影响

标签:choiceIndex,概率,random,重选,carIndex,问题,三门,total
From: https://www.cnblogs.com/tensorzhang/p/16849387.html

相关文章