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
- 浏览: 1018689 次
文章分类
最新评论
-
18335864773:
很多公司项目 都在使用pageoffice 来操作word,e ...
用java生成word文档 -
Gozs_cs_dn:
请问下博主, 怎样将sitemesh3.xsd绑定 sitem ...
SiteMesh3配置 -
Rose_06:
springside4.0quick-start.bat报错原因 -
ilemma:
我也是刚参见工作啊,经理让自学这个,有些东西不太懂,能不能发个 ...
Apache Shiro在Web中的应用 -
shanbangyou:
你废了
程序员上班打酱油的方法
发表评论
-
递归归并排序
2016-02-11 20:26 355/* MergeSort.java CSC 225 - ... -
java冒泡排序对布尔类型进行排序
2015-12-11 23:06 649QQ 928900200 程序代写 java不能对 ... -
判断宏是否是“安全”的
2014-11-22 22:54 569给了一系列C++的宏定义,问你一个表达式是否是“安全”的。 ... -
C语言求平均值
2014-11-19 19:14 569木其工作室:QQ928900200 Computing I ... -
C语言连连看
2014-11-18 16:34 608(1)定义一个矩阵,随机产生字符布置地图,例如下面这个4x ... -
c语言二叉树
2014-10-19 11:39 452木其工作室 http://www.xmsydw.com ... -
java类
2014-10-16 08:27 310木其工作室 qq 928900200 You are ... -
ECE/CPSC 3520
2014-10-13 09:49 551ECE/CPSC 3520Fall 2014Software ... -
计算机安全
2014-10-07 14:52 447CS461 MP 1: Due Wednesday 09/17 ... -
java星球机器人建模UML
2014-10-06 22:29 410Your task is to design and imp ... -
数据库sql
2014-10-06 22:25 625service QQ 928900200 ... -
C语言 cgi(3)
2014-08-04 09:17 3611cs3157 – Advanced ProgrammingS ... -
C语言 cgi(2)
2014-08-04 09:10 3121Columbia Universitycs3157 – Ad ... -
C语言cgi(1)
2014-08-04 09:08 3431Columbia Universitycs3157 – Ad ... -
c++ input,output
2014-08-04 08:37 484You should be comfortable w ... -
Array of Objects
2014-08-04 08:30 673You should be comfortable w ... -
bat脚本打开网页
2014-07-13 09:54 893start iexplore "http://ww ... -
java 汉诺塔实现自动演示
2014-07-10 11:53 5171、增加计时功能,显 ... -
代写java程序qq:928900200
2014-06-18 12:46 3学校为全面提升学校教学质量,提高管理水平,决定开发一套小型成 ... -
基于MVC的系统代写
2014-06-16 12:13 451人力资源管理系统 完成系统静态页面设计,页面数 ...
相关推荐
Monty Hall Problem.py
蒙提霍尔问题(Monty Hall Problem)是概率论领域内一个著名的悖论性问题,以其独特的解决方法和对直觉的挑战而闻名。这个问题最初来源于美国电视节目《Let’s Make a Deal》,该节目的主持人正是蒙提·霍尔(Monty ...
蒙蒂·霍尔问题背景信息: 根据著名的游戏节目,参赛者可以选择在3个门之间进行选择两扇门中有山羊,如果选择了其中两扇门,则参赛者将输掉比赛一扇门装满了钱,这就是选手所渴望的规则: 参赛者随机选择一扇关门,...
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问题:有三扇门,门后分别放有一辆汽车和两只羊。你有机会任意选择其中一扇门,并得到门后的礼物。当你选择了一扇门后,主持人并不直接打开这扇门,而是打开另外一扇放有羊的门给你看。此时,给你一次改变...
“蒙特霍问题”(The Monty Hall Problem),您是一个电视游戏的参加者,并有机会赢得大奖。在那你面前有三扇关闭着的门,一扇门后面是一辆崭新的汽车,另外两扇门后面则是一些安慰奖。奖品的位置是随机选择的。节目...
7. **The Monty Hall Problem and the Chance Server**(蒙特霍问题和机会服务器): - 蒙特霍问题是一个经典的概率问题,展示了概率理解的重要性。通过这个问题,用户可以学习到条件概率和最优决策策略,同时也可...
蒙蒂霍尔问题可视化Monty Hall问题的命名与Monty Hall主持的“让我们做交易”电视游戏节目相似。 问题是语句如下。 假设一个房间装有三扇门。 在两个后面是山羊,在第三个后面是一辆闪亮的新车。 要求您选择一扇门,...
三门问题(Monty Hall problem)亦称为蒙提霍尔问题、蒙特霍问题或蒙提霍尔悖论,大致出自美国的电视游戏节目Let's Make a Deal。问题名字来自该节目的主持人蒙提·霍尔(Monty Hall)。参赛者会看见三扇关闭了的门...
在信息技术领域,我们经常遇到各种有趣的问题,而“蒙提霍尔问题”(Monty Hall Problem)就是其中之一。它源于美国电视游戏节目,蕴含了概率论和决策理论的基本原理。在这个问题中,我们要探讨如何通过数学模型来...
stay_probability, switch_probability = monty_hall_simulation(100000) print(f"坚持选择获胜概率: {stay_probability * 100:.2f}%") print(f"改变选择获胜概率: {switch_probability * 100:.2f}%") ``` 这个程序...
《蒙蒂霍尔问题模拟——理解概率与决策的智慧》 在概率论和决策理论领域,蒙蒂霍尔问题一直是一个备受关注的话题。该问题以其简单的规则和复杂的概率特性,吸引了众多学者和爱好者的探索与研究。...
Monty Hall问题是游戏节目中一个著名的小难题。 它是这样的:您将看到3个门。 在两个后面是山羊,在第三个后面是汽车。 要求您选择一扇门; 如果您选择带车门,您将获胜! 选择后,房主随后打开其余两扇门中的一扇,...
这个名为"Monty-Hall-Problem-Swift"的项目,提供了一个用Swift实现的三门问题演示Playground,其中还包含中文注释,方便初学者理解和学习。 一、三门问题简述 三门问题的基本设定是:参赛者面前有三扇关闭的门,...
蒙提·霍尔问题(Monty Hall Problem)源于美国电视游戏节目《Let's Make a Deal》的主持人Monty Hall,它是一个概率论中的经典问题,涉及到条件概率和决策理论。在这个问题中,参赛者面前有三扇关闭的门,其中一扇...
蒙蒂霍尔问题 ... 它基本上是游戏的模拟,有三个门和一个“隐藏奖品”按钮。 在浏览器控制台中,“隐藏对象”一“隐藏”就可以看到,由 3 个门组成的数组表示,其中 1 = 奖品(汽车),0 = 无奖品(山羊)。
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的代码蒙蒂霍尔问题 你明白了。 电视节目。 3 扇门为您打开,1 扇有终身不和谐硝基,2 扇有 belle delphine 小便水。 现在你想要 belle delphine 的小便水,因为我们很简单。 不,你想要硝基。...
本篇将重点探讨如何利用Matlab来模拟和理解著名的“蒙特霍尔问题”(Monty Hall Problem)。 蒙特霍尔问题源自一个电视游戏节目,它涉及到概率和决策理论。在这个游戏中,参赛者面前有三扇关闭的门,其中一扇门后面...
标题中的"change_or_not_test.rar_matlab游戏"指的是一个基于MATLAB编程环境设计的游戏,它模拟了著名的“蒙提霍尔问题”(Monty Hall Problem)。这个游戏是一个概率实验,涉及到了决策理论和统计学概念。 描述中...