Re: [問卦] 三扇門的問題 33.3% or 50%
※ 引述《Zoro777 (快樂會傳染^^)》之銘言:
: 猜到送大獎的遊戲裡 有三扇門 門後總共有兩隻羊 一台車
: 猜到車的那扇門就可以把車開回家
: 有三扇門 答題者 首先選了第一扇
: 後來主持了開了第三扇門 門後是頭羊
: 主持人問答題者 要不要換
: 答題者說他要換 他說從理論分析
: 一開始選中車子的機率是33.3%
: 後來開了第三扇門之後
: 選擇換又是車子的機率變成了66.6%
: 所以他選擇換....結果聽說這居然是正解...
: 我就他媽的問一句 為什麼不是50% 剩下兩扇門
: 一個是羊 一個是車
: 是不是他媽的說了一個很難被大眾接受的答案 才能顯得牛逼
安安,理論鄉民都回很多了,其實我們自己玩個十萬次就好啦
先決定有幾扇門,然後先隨機選個答案
法一:再隨便選扇門,直接對答案
法二:主持人從非答題者選的門以及正確答案中,再隨機選出一扇門打開
接著答題者從非自己第一次選的門,以及非剛才主持人選的門中,
再選擇一扇門做答案
我寫程式跑了十萬次,法一約是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), 來自: 111.241.104.157 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Gossiping/M.1628990689.A.992.html
噓
08/15 09:26,
2年前
, 1F
08/15 09:26, 1F
推
08/15 09:33,
2年前
, 2F
08/15 09:33, 2F
推
08/15 09:55,
2年前
, 3F
08/15 09:55, 3F
推
08/15 09:58,
2年前
, 4F
08/15 09:58, 4F
→
08/15 12:58,
2年前
, 5F
08/15 12:58, 5F
都生兩個了,沒什麼好過情人節了啦嗚嗚
推
08/15 15:50,
2年前
, 6F
08/15 15:50, 6F
咦幫忙檢查下你是不是remove_choices = list(range(DOORS))沒貼到?
※ 編輯: supernick (111.241.104.157 臺灣), 08/15/2021 18:27:09
推
08/15 20:08,
2年前
, 7F
08/15 20:08, 7F
討論串 (同標題文章)