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, ...
随机推荐
- 关于在xml文件中的 error: invalid symbol: 'switch' 错误
在xml布局文件中使用Switch控件时,出现error: invalid symbol: 'switch'报错,代码如下: <Switch android:id="@+id/swit ...
- OpenGL(二)——函数库简述
简述 1. OpenGL用到的库分为OpenGL核心库.OpenGL实用库.OpenGL辅助库和OpenGL工具库(不是必须) 2. OpenGL核心库 核心库包含有115个函数,函数名的前缀为gl ...
- C++语法之-------strcpy,memcpy,memset
1.strcpy 原型:extern char *strcpy(char *dest,char *src); 用法:#i nclude 功能:把src所指由NULL结束的字符串复制到dest所指的数组 ...
- 【Python自动化运维之路Day2】
1. 常量命名规则 在Python中,会在变量命名上标明某变量是常量,通常采用全是大写的方式来标明,如: CONNECT= '127.0.0.1' PORT = ' 2.Python编译 python ...
- golang 值得注意的地方(2则)
golang 的语法和使用方式都非常简单明了,没有花哨的语法糖,也没有多余的关键字. 但是即使是这么简洁的语言,仍然有一些不那么直白,需要注意的地方,比如下面2点. interface 赋值 nil ...
- 入门级:怎么使用C#进行套接字编程(一)
翻译一篇简单的文章学习下基础,此文针对我等对socket只听说未尝试阶段的水平. How to C# Socket programming C#通过他的命名空间像System.Net和System.N ...
- (转)基于OWIN WebAPI 使用OAuth授权服务【客户端模式(Client Credentials Grant)】
适应范围 采用Client Credentials方式,即应用公钥.密钥方式获取Access Token,适用于任何类型应用,但通过它所获取的Access Token只能用于访问与用户无关的Open ...
- C#中Encoding.Unicode与Encoding.UTF8的区别
今天在园子首页看到一篇博文-简单聊下Unicode和UTF-8,从中知道了UTF-8是Unicode的一种实现方式: Unicode只是给这世界上每个字符规定了一个统一的二进制编号,并没有规定程序该如 ...
- 2014年市场需求排名前10的编程语言 - 生命的延续是 BI
开篇介绍 2014年就快收尾了,Team 内部每人都会准备一些 Tech Talk 的内容,技术方面的,咨询方面的都可以.我就准备了一些有关 BI 排名,BI 报表排名,包括各种技术编程语言等相关排名 ...
- SublimeText2 快捷键一览
ctrl+shift+w: 关闭Sublime,关闭所有打开文件ctrl+n: 新建文件ctrl+s: 保存ctrl+shift+s: 另存为ctrl+f4: 关闭文件ctrl+w: 关闭f11: 切 ...