PTT推薦

Re: [問卦] 三扇門的問題 33.3% or 50%

看板Gossiping標題Re: [問卦] 三扇門的問題 33.3% or 50%作者
vzerov
(阿阿)
時間推噓 2 推:2 噓:0 →:0

※ 引述《panex0845 (胖克思)》之銘言:
: 我原本也是相信機率會從33%變成66%所以要換的
: 可是我發現,
: 如果把門的數量提高到100扇
: 程式跑出來的結果兩者趨近於1
: 那不就是50/50嗎?八卦?
: ※ 引述《supernick (尼克黃)》之銘言:
: : 安安,理論鄉民都回很多了,其實我們自己玩個十萬次就好啦
: : 先決定有幾扇門,然後先隨機選個答案
: : 法一:再隨便選扇門,直接對答案
: : 法二:主持人從非答題者選的門以及正確答案中,再隨機選出一扇門打開
: : 接著答題者從非自己第一次選的門,以及非剛才主持人選的門中,
: : 再選擇一扇門做答案
: : 我寫程式跑了十萬次,法一約是33.3%,法二約是66.6%啦
: : 對python不熟,code在下面,請廣大鄉民幫我debug感恩
: : 不會寫程式或沒有環境朋友,也可以把code貼到下面這連結玩玩看
: : https://www.programiz.com/python-programming/online-compiler/
: : ----
: : import random
: : # construct n doors in game
: : DOORS = 3
: : PLAY_TIMES = 100000
: : win_times_1 = 0
: : win_times_2 = 0
: : for i in range(PLAY_TIMES):
: : door = list(range(DOORS))
: : # the game host chooses answer
: : answer = random.choice(door)
: : # the player picks one door randomly as his/her answer
: : pick = random.randint(0, DOORS-1)
: : # case 1: player does not change decision
: : if pick == answer:
: : win_times_1 += 1
: : # case 2: player changes decision after host revealed one of the answer: : # pick remove door and then remove from choices. cannot be answer or pick
: : remove_choices = list(range(DOORS))
: : remove_choices.remove(answer)
: : if answer != pick:
: : remove_choices.remove(pick)
: : remove_door = random.choice(remove_choices)
: : # remove the door from list
: : door.remove(remove_door)
: : # remove original answer
: : door.remove(pick)
: : # player picks a door again
: : pick = random.choice(door)
: : if pick == answer:
: : win_times_2 += 1
: : print("No Change Winning Percentage: ", win_times_1/PLAY_TIMES * 100)
: : print("Change Door Winning Percentage:", win_times_2/PLAY_TIMES * 100)

趨近於一是因為這程式寫的是主持人只移掉一扇門
選擇者要換門還是從剩下的門重選一個
100扇門移掉一扇還是剩99扇 當然你換不換都會接近1%勝率 換還是高點
我改了一下換成主持人全部移掉只留兩扇的版本 你可以試試看


import random

# construct n doors in game
DOORS = 100
PLAY_TIMES = 10000
win_times_1 = 0
win_times_2 = 0

for i in range(PLAY_TIMES):
door = list(range(DOORS))

# the game host chooses answer
answer = random.choice(door)

# the player picks one door randomly as his/her answer
pick = random.randint(0, DOORS-1)

# case 1: player does not change decision
if pick == answer:
win_times_1 += 1

# case 2: player changes decision after host revealed one of the answer
# pick remove door and then remove from choices. cannot be answer or pick remove_choices = list(range(DOORS))
remove_choices.remove(answer)
if answer != pick:
remove_choices.remove(pick)

for ii in range(DOORS-2):

remove_door = random.choice(remove_choices)

# remove the door from list
door.remove(remove_door)
remove_choices.remove(remove_door)

# remove original answer
door.remove(pick)
# player picks a door again
pick = random.choice(door)

if pick == answer:
win_times_2 += 1

print("No Change Winning Percentage: ", win_times_1/PLAY_TIMES * 100)
print("Change Door Winning Percentage:", win_times_2/PLAY_TIMES * 100)

--

※ PTT留言評論
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.136.54.13 (臺灣)
PTT 網址

ffdqfe 08/16 04:20啊…這個話題已經進展成這樣了啊

mikezip 08/16 09:20寫這些給推