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, ...
随机推荐
- UITableView动态存放、重用机制
一.UITableView动态存放 #import "ViewController.h"@interface ViewController ()<UITableViewDel ...
- 【整理】-- C++ 多线程
os:ubuntu c++ 1.创建线程 #include <iostream> #include <pthread.h> //多线程相关操作头文件,可移植众多平台 usi ...
- Xshell_Using X11 forwarding
FROM:http://www.netsarang.com/tutorial/xshell/1018/Using_X11_forwarding The X11 forwarding feature i ...
- (转)基于OWIN WebAPI 使用OAuth授权服务【客户端模式(Client Credentials Grant)】
适应范围 采用Client Credentials方式,即应用公钥.密钥方式获取Access Token,适用于任何类型应用,但通过它所获取的Access Token只能用于访问与用户无关的Open ...
- 想抛就抛:Application_Error中统一处理ajax请求执行中抛出的异常
女朋友不是想抛就抛,但异常却可以,不信请往下看. 今天在MVC Controller中写代码时,纠结了一下: public async Task<ActionResult> Save(in ...
- C#,Java,C -循环冗余检验:CRC-16-CCITT查表法
C#代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...
- JavaScript实用技巧总结
前言 总结一下最近接触到的JavaScript语法糖,与大家共享. 每块糖都有详细的说明和示例,就不多说了. 准确的类型检查 /* * @function: * 类型检查示例 * 通过此方法,可以检查 ...
- redmine 一键安装
Redmine 是一个开源的.基于Web的项目管理和缺陷跟踪工具.它用日历和甘特图辅助项目及进度可视化显示.同时它又支持多项目管理.Redmine是一个自由开放 源码软件解决方案,它提供集成的项目管理 ...
- paip. 混合编程的实现resin4 (自带Quercus ) 配置 php 环境
paip. 混合编程的实现resin4 (自带Quercus ) 配置 php 环境 #---混合编程的类型 1.代码inline 方式 2.使用库/api 解析方式. #----配置resin 支 ...
- MySQL分区表
当数据库数据量涨到一定数量时,性能就成为我们不能不关注的问题,如何优化呢? 常用的方式不外乎那么几种: 1.分表,即把一个很大的表达数据分到几个表中,这样每个表数据都不多. 优点:提高并发量,减小锁的 ...