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

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

    蒙提霍尔问题(Monty Hall Problem)是概率论领域内一个著名的悖论性问题,以其独特的解决方法和对直觉的挑战而闻名。这个问题最初来源于美国电视节目《Let’s Make a Deal》,该节目的主持人正是蒙提·霍尔(Monty ...

    monty_hall_problem:Python中的Monty Hall问题

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

    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),您是一个电视游戏的参加者,并有机会赢得大奖。在那你面前有三扇关闭着的门,一扇门后面是一辆崭新的汽车,另外两扇门后面则是一些安慰奖。奖品的位置是随机选择的。节目...

    数学网站集锦,很不错

    7. **The Monty Hall Problem and the Chance Server**(蒙特霍问题和机会服务器): - 蒙特霍问题是一个经典的概率问题,展示了概率理解的重要性。通过这个问题,用户可以学习到条件概率和最优决策策略,同时也可...

    蒙蒂霍尔问题可视化

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

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

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

    The-Monty-Hall-Problem-modeling

    在信息技术领域,我们经常遇到各种有趣的问题,而“蒙提霍尔问题”(Monty Hall Problem)就是其中之一。它源于美国电视游戏节目,蕴含了概率论和决策理论的基本原理。在这个问题中,我们要探讨如何通过数学模型来...

    the_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-Problem-Simulation

    《蒙蒂霍尔问题模拟——理解概率与决策的智慧》 在概率论和决策理论领域,蒙蒂霍尔问题一直是一个备受关注的话题。该问题以其简单的规则和复杂的概率特性,吸引了众多学者和爱好者的探索与研究。...

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

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

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

    这个名为"Monty-Hall-Problem-Swift"的项目,提供了一个用Swift实现的三门问题演示Playground,其中还包含中文注释,方便初学者理解和学习。 一、三门问题简述 三门问题的基本设定是:参赛者面前有三扇关闭的门,...

    Monty_Hall

    蒙提·霍尔问题(Monty Hall Problem)源于美国电视游戏节目《Let's Make a Deal》的主持人Monty Hall,它是一个概率论中的经典问题,涉及到条件概率和决策理论。在这个问题中,参赛者面前有三扇关闭的门,其中一扇...

    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 的小便水,因为我们很简单。 不,你想要硝基。...

    matlab开发-montyHall

    本篇将重点探讨如何利用Matlab来模拟和理解著名的“蒙特霍尔问题”(Monty Hall Problem)。 蒙特霍尔问题源自一个电视游戏节目,它涉及到概率和决策理论。在这个游戏中,参赛者面前有三扇关闭的门,其中一扇门后面...

    change_or_not_test.rar_matlab游戏

    标题中的"change_or_not_test.rar_matlab游戏"指的是一个基于MATLAB编程环境设计的游戏,它模拟了著名的“蒙提霍尔问题”(Monty Hall Problem)。这个游戏是一个概率实验,涉及到了决策理论和统计学概念。 描述中...

Global site tag (gtag.js) - Google Analytics