`
guoyiqi
  • 浏览: 966318 次
社区版块
存档分类
最新评论

The Monty Hall Problem

 
阅读更多

GNG1106 Lab 3
The Monty Hall Problem
Background
The Monty Hall Problem is a famous probability puzzle, based on an old television show, in which the host,
Monty Hall, plays a game with a player. It goes like this: In each game, three doors are presented to the
player, where behind one of the three doors, there is a prize and behind the other two doors there is nothing.
Monty Hall then asks the player to pick a door; the game rule is that the player will be given the prize if he
picks the door behind which there is the prize. After the player picks a door, say Door 1, Monty Hall will
take a peek at what is behind the other two doors and open one of them. He would say, \Look, there is no
prize behind this door!". Note that since only one door has a prize, it is always possible for Monty Hall to
pick a door that the player did not pick and that has no prize. Suppose that the door he opens is Door 2.
Monty Hall then goes on and says, \I am going to make you a deal: I will allow you to change your decision
by switching your pick to the other door (in this example, to Door 3). Do you want to do that?" It is up
to the player to decide if he wants to switch to Door 3 or to stay with Door 1. After the player makes his
switch-or-not-switch decision, Monty Hall opens the door of the player's nal choice, and the player will get
a prize if an only if there is the prize behind the door of his choice.
Historically there were intense debates on whether switching would improve the chance of winning, which
made the TV show very popular. In this lab, you are to develop a program that simulate the Monte Hall
game and investigate this problem by yourself.
Description
The program you are to write include two modes: game mode and research mode. Brie
y, in the game mode,
the program will act as Monty Hall and plays the game with the program user; in the research mode, the
program allows the user to study what is the probability of winning the prize for the always-switch strategy
and for the never-switch strategy.
When the program runs, it rst prints a menu and prompts user to select an option:
Enter one of the following options:
1. Game Mode
2. Research Mode
3. Exit
Only when the user chooses to exit will the program exit. If the user chooses the game mode and nishes
playing a game, the program comes back to this menu and prompts the user to enter an option again.
Similarly, if the user chooses the research mode and nishes the research on either one of the two strategies,
the program also comes back to this menu and prompts the user again.
Game Mode
In the game mode, the program acts as Monty Hall and simulates ONE game play with the user.
1The three doors will be denoted by Door 1, Door 2 and Door 3. The program starts by selecting a door
from the three at (uniformly) random and \putting" the prize behind that door. It then asks the user to
pick a door. After the user makes his pick, the program, based on what the user picks, \opens" a door that
user did not pick and that has no prize behind it, and then asks the user if he wants to switch. After the
user makes his switch-or-not-switch decision, the program reveals where is the prize and announces if the
user has won.
In addition to this main task, the total number of games that the user has played in the game mode and
the number of times he wins should also be counted and printed out after each game. Note that even if a
user leaves the game mode to access the research mode, his game play statistics in the game mode (namely,
total number of games played and the number of winnings in the game mode so far) should still be kept, so
that when the user comes back to the game mode and play the game again, the counting can be continued.
Research Mode
In the research mode. the program rst prompts the user to select from one of the two playing strategies, the
always-switch strategy and the never-switch strategy. It also asks the user to enter the number N of game
plays that the user would like to simulate for that strategy. Then for the selected strategy, the program
simulates N game plays using that strategy.
In each game play, the program again acts as Monty Hall except that
1. no message is printed;
2. the program always sets the player's initial pick to Door 1;
3. if the \never-switch" strategy is simulated, the program sets the player's switch-or-not-switch choice
always to \not switch"; if the \always-switch" strategy is simulated, program sets the player's switch-
or-not-switch choice always to \switch".
That is, in the research mode, the actions of the player are also simulated by the program and there is
no need for the user to enter anything in a game play.
After the simulation of N game plays, the program prints the percentage of games in which the user wins
(which approximates the probability of winning, for large N).
Requirements
In addition to the regular requirements for labs, this lab requires you to modularize your code in terms of
functions. In particular, noting that the game mode and the research mode have signi cant commonality,
you should extract the common parts into function(s) and call them in both modes of the program.
In Step 3 of the lab where you need to develop a
ow chart (or algorithm/pseudo code), it is better to
split the
ow chart into several
ow charts hierarchically, namely, you may want to develop a high-level
ow
chart for the overall program and two
ow charts each for a program mode. In addition, for each function
you are to create, you should also develop a
ow chart.
2

分享到:
评论

相关推荐

    Monty Hall Problem.py

    Monty Hall Problem.py

    monty_hall_problem:Python中的Monty Hall问题

    蒙蒂·霍尔问题背景信息: 根据著名的游戏节目,参赛者可以选择在3个门之间进行选择两扇门中有山羊,如果选择了其中两扇门,则参赛者将输掉比赛一扇门装满了钱,这就是选手所渴望的规则: 参赛者随机选择一扇关门,...

    monty hall

    Good probability problem

    Impractical Python Projects (2018.11出版,EPUB格式)

    Help the world’s smartest woman win the Monty Hall problem argument Reveal Jupiter’s Great Red Spot using optical stacking Save the head of Mary, Queen of Scots with steganography Simulate volcanoes...

    车羊问题(Monty Hall)问题C模拟

    Monty Hall问题:有三扇门,门后分别放有一辆汽车和两只羊。你有机会任意选择其中一扇门,并得到门后的礼物。当你选择了一扇门后,主持人并不直接打开这扇门,而是打开另外一扇放有羊的门给你看。此时,给你一次改变...

    蒙特霍问题

    “蒙特霍问题”(The Monty Hall Problem),您是一个电视游戏的参加者,并有机会赢得大奖。在那你面前有三扇关闭着的门,一扇门后面是一辆崭新的汽车,另外两扇门后面则是一些安慰奖。奖品的位置是随机选择的。节目...

    The-Monty-Hall-Problem-modeling

    The-Monty-Hall-Problem-modeling

    蒙蒂霍尔问题可视化

    蒙蒂霍尔问题可视化Monty Hall问题的命名与Monty Hall主持的“让我们做交易”电视游戏节目相似。 问题是语句如下。 假设一个房间装有三扇门。 在两个后面是山羊,在第三个后面是一辆闪亮的新车。 要求您选择一扇门,...

    三门问题,蒙特霍尔问题的Python程序

    三门问题(Monty Hall problem)亦称为蒙提霍尔问题、蒙特霍问题或蒙提霍尔悖论,大致出自美国的电视游戏节目Let's Make a Deal。问题名字来自该节目的主持人蒙提·霍尔(Monty Hall)。参赛者会看见三扇关闭了的门...

    the_monty_hall_problem

    蒙蒂·霍尔问题(模拟) 这个项目展示了一个令人着迷的蒙蒂·霍尔(Monty Hall)问题的模拟。您可以找到有关以下内容的详细信息:

    Monty-Hall-Problem-Simulation

    蒙蒂霍尔问题模拟 这是一个模拟网站。 这是的模拟 运行测试 你可以通过玩模拟,或者如果你有一个安卓手机,你可以通过这个链接下载游戏。 内置 致谢

    Monty-Hall-Problem-Swift:三门问题的Swift验证演示Playground,在原作者的基础上添加了中文注释

    Monty-Hall-Problem-Swift 三门问题的Swift验证演示Playground,在原作者的基础上添加了中文注释

    dsc-monty-hall-problem-lab-onl01-dtsc-pt-041320

    Monty Hall问题是游戏节目中一个著名的小难题。 它是这样的:您将看到3个门。 在两个后面是山羊,在第三个后面是汽车。 要求您选择一扇门; 如果您选择带车门,您将获胜! 选择后,房主随后打开其余两扇门中的一扇,...

    Monty-Hall-Problem:使用 JavaScript 重现蒙蒂霍尔问题

    蒙蒂霍尔问题 ... 它基本上是游戏的模拟,有三个门和一个“隐藏奖品”按钮。 在浏览器控制台中,“隐藏对象”一“隐藏”就可以看到,由 3 个门组成的数组表示,其中 1 = 奖品(汽车),0 = 无奖品(山羊)。

    Artificial Intelligence and Problem Solving

    10 Monty Hall Problem......Page 194 PrOBLem-sOLvinG Techniques......Page 195 humAn PrOBLem sOLvinG......Page 197 reLATeD PrOBLems......Page 198 references......Page 199 11 Rubik Cube......Page 200 ...

    贝岭的matlab的代码-Monty-Hall-Problem:蒙蒂霍尔问题

    贝岭的matlab的代码蒙蒂霍尔问题 你明白了。 电视节目。 3 扇门为您打开,1 扇有终身不和谐硝基,2 扇有 belle delphine 小便水。 现在你想要 belle delphine 的小便水,因为我们很简单。 不,你想要硝基。...

    Mathematics for Computer Science 2017.7z

    18.1 Monty Hall Confusion 18.2 定义和符号(Definition and Notation) 18.3 条件概率的四步法(The Four-Step Method for Conditional Probability) 18.4 为什么树状图如此有效(Why Tree Diagrams Work) 18.5 ...

    计算机随机数模拟随机试验教学设计.docx

    学习活动设计 教师活动 学生活动 环节一:创设情境,激发兴趣 教师活动1 引入情景问题,引发学生思考 三门问题(Monty Hall problem),是一个源自博弈论的数学游戏问题,大致出自美国的电视游戏节目Let's Make a ...

    Python_training

    Python_training bmi-BMI程序(如果有判断) 驾驶-年纪(多层if判断) guess_number-猜数字(如果和同时) guess_password-猜密码(如果有) Monty_Hall_Problem-三门问题的频率(随机) 产品-记事(同时) Python_...

    蒙蒂霍尔悖论模拟:我需要一种动手方法来了解蒙蒂霍尔悖论背后的概率。-matlab开发

    该程序用于模拟此处描述的场景 ( https://en.wikipedia.org/wiki/Monty_Hall_problem ) 并最终表明玩家确实有 2/3 的获胜机会,只要他们总是选择换门 (与普遍的误解相反,即有 50/50 的机会选择正确的门)。

Global site tag (gtag.js) - Google Analytics