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 signicant 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
The Monty Hall Problem的更多相关文章
- 羊和汽车问题(或s三门问题(Monty Hall problem)亦称为蒙提霍尔问题)
三门问题(Monty Hall problem)亦称为蒙提霍尔问题.蒙特霍问题或蒙提霍尔悖论,大致出自美国的电视游戏节目Let's Make a Deal.问题名字来自该节目的主持人蒙提·霍尔(Mon ...
- 用贝叶斯定理解决三门问题并用Python进行模拟(Bayes' Rule Monty Hall Problem Simulation Python)
三门问题(Monty Hall problem)也称为蒙提霍尔问题或蒙提霍尔悖论,出自美国的电视游戏节目<Let’s Make a Deal>.问题名字来自该节目的主持人蒙提·霍尔(Mon ...
- Monty Hall Problem (三门问题)
最近有点忙,没怎么写程序...今天突然想起以前看到过的一个问题-三门问题,十分想用程序来模拟一下,于是实在忍不住了就模拟了这个游戏的实验,通过写程序更加加深了我对这个问题的理解,期间也查找了各种相关资 ...
- sql server:Monty Hall problem (蒙提霍尔问题)
--------------------------------------------------------------------- -- Auxiliry Table of Numbers 数 ...
- Monty 大厅问题(Monty Hall Problem)也称作三门问题,出自美国大型游戏节目 Let's Make a Deal。
Monty 大厅的问题陈述十分简单,但是它的答案看上去却是有悖常理.该问题不仅引起过很多争议,也经常出现在各种考试题中. Monty 大厅的游戏规则是这样的,如果你来参加这个节目,那么 (1)Mont ...
- Monty Hall Problem的一个图解,感觉不错
从Coursera.org上的台大概率课讨论组里拿来的 如果不转换,选中汽车的概率是1/3,非常显然. 但转换后选中汽车的概率变成2/3就有点反直觉了,并不是太容易想明白. 因为转换其实有4种:汽车- ...
- Monty Hall 问题与贝叶斯定理的理解
三门问题(Monty Hall problem),是一个源自博弈论的数学游戏问题,大致出自美国的电视游戏节目Let's Make a Deal.问题的名字来自该节目的主持人蒙提·霍尔(Monty H ...
- zzulioj--1712--Monty Hall problem(蒙提霍尔问题)
1721: Monty Hall problem Time Limit: 1 Sec Memory Limit: 128 MB Submit: 186 Solved: 71 SubmitSt ...
- 回顾 Monty Hall (三门问题)
一.问题描述 Monty Hall Problem 源于美国的一档电视节目<Let's Make a Deal>,其中Monty Hall 是这个节目的主持人. 节目中有三扇门1.2.3, ...
随机推荐
- MyBatis学习之路之configuration配置
1.首先讲解的是MyBatis核心配置文件configuration.xml的配置 一个完整的configuration.xml配置顺序如下: properties,settings,typeAlia ...
- 使用的组件:Web Uploader
Web UploaderWebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件.在现代的浏览器里面能充分发挥HTML5的优势, ...
- LDO-XC6216C202MR-G
XC6216C202MR-G 1.改产品是特瑞士(TOREX)公司电源管理芯片,输入电压可达28V,输出可调23V,最大输出电流150mA.压差最小为300mV.该系列有固定式输出和可调式 ...
- poj 1936 All in All
All in All Time Limit: 1000 MS Memory Limit: 30000 KB 64-bit integer IO format: %I64d , %I64u Java ...
- 使用 Microsoft Fakes 进行单元测试
本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 在编写单元测试时,我们会遇到不同的外部依赖项,大体上可以分为两类: 依赖于接口或抽象类 依赖于具体类 ...
- 在Eclipse添加Android兼容包( v4、v7 appcompat )
昨天添加Android兼容包,碰到了很多问题,在这里记录一下,让后面的路好走. 如何选择兼容包, 请参考Android Support Library Features(二) 一.下载Support ...
- HTML5 Canvas实现黑客帝国文字掉落效果
效果: 原理: 用canvas逐行输出文字,然后让背景颜色逐渐加深,再随机中断某些列. 代码: HTML: <canvas id="c"></canvas> ...
- javascript跨域通信(二):window.name实现的跨域数据传输
首先了解一下window.name这个东西是什么. name 在浏览器环境中是一个全局/window对象的属性,当在 frame 中加载新页面时,name 的属性值依旧保持不变 并且name 属性仅对 ...
- 博客搬家了,欢迎访问 http://blog.csdn.net/yinpengxiang/
博客搬家了,欢迎访问 http://blog.csdn.net/yinpengxiang/
- paip.log4j兼容linux windows 路径设置
paip.log4j兼容linux windows 路径设置 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog ...