切换策略下的胜率
现在,我们来编写代码:参赛者最初选择 1 号门,在山羊被揭示后,切换到剩下的那扇门。
同样,先只编码单次迭代。然后将其放入一个 for 循环中反复运行,从而得到对真实胜率的模拟估计。
本练习是课程的一部分
R 中的概率谜题
交互式实操练习
通过完成这段示例代码来试试这个练习。
set.seed(1)
prize <- sample(doors,1)
initial_choice <- 1
# Use the reveal_door function to do the reveal
reveal <- reveal_door(___, ___, ___)
# Switch to the remaining door
final_choice <- ___
print(final_choice)
# Check whether the final choice equals the prize
if(___){
print("The final choice is correct!")
}