精華區beta Gossiping 關於我們 聯絡資訊
我原本也是相信機率會從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) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.34.215.74 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Gossiping/M.1629055447.A.B3A.html
rex9999: 無論設計多少門 最終永遠二擇一 1.164.126.233 08/16 03:27
xiemh420: 代表程式寫錯了 114.36.119.229 08/16 03:33
babyalley: 我記得最終都是要2擇1 所以如果你設計114.137.184.110 08/16 03:33
babyalley: 100道門 你會先選1門 然後開剩下的門114.137.184.110 08/16 03:33
babyalley: 中的98道門 之後再問你要不要換114.137.184.110 08/16 03:33
kurtsgm: 啊就代表他寫錯了啊 XD 220.129.201.19 08/16 03:34
xiemh420: 100道門 換門的勝率是99% 114.36.119.229 08/16 03:38
Armour13: 這串文幹嘛討論這麼久 114.34.80.22 08/16 03:41