This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS1132 Fall 2009 Assignment 1 Adhere to the Code of Academic Integrity. You may discuss background issues and general solution strategies with others and seek help from course staff, but the homework you submit must be the work of just you. When submitting your assignment, be careful to follow the instructions summarized in Section 4 of this document. 1 The Monty Hall Dillemma You may have heard about the Monty Hall problem. It takes its name from the host of the American television show Let’s Make a Deal . The problem has been formulated as follows: “ Suppose you’re on a game show and you’re given the choice of three doors. Behind one door is a car; behind the others, goats. The car and the goats were placed randomly behind the doors before the show. The rules of the game show are as follows: After you have chosen a door, the door remains closed for the time being. The game show host, Monty Hall, who knows what is behind the doors, now has to open one of the two remaining doors, and the door he opens must have a goat behind it. If both remaining doors have goats behind them, he chooses one randomly. After Monty Hall opens a door with a goat, he will ask you to decide whether you want to stay with your first choice or to switch to the last remaining door. Imagine that you chose Door 1 and the host opens Door 3, which has a goat. He then asks you “Do you want to switch to Door Number 2 ?” 1 Here is a short visual explanation of the problem. 1.1 Programming the game Your first task is to program an interactive version of the game, where the code/computer is the host and the user is the player. Your code should ask the user for a first guess (a number from 1 to 3), open a door with a goat for the user, ask the user if s/he wants to switch and then communicate the outcome, i.e. , car or goat. Ask the user if s/he wants to play again. Save your script in montyHallInteractive.m . Below is a possible scenario for this interaction: >> montyHallInteractive Hello and welcome to the game! Please choose one of the three doors: 3 You have chosen door number 3. Door number 1 has a goat behind it! Would you like to switch from door 3 to door 2?(y/n) y Sorry, you lost. Door number 3 has the car :| Would you like to play again?(y/n) n Good bye! You may be asking yourself: should the person switch or not? Do the odds of wining change after one door has been opened? There are two ways of thinking about this: • There is a 1/3 chance that the player will pick the prize door, and a 2/3 chance that s/he will miss the prize. Not switching means 1/3 is the probability to get the prize. However, if s/he missed (and this event has a 2/3 probability), then the prize is behind one of the remaining two doors. Furthermore, of these two, the host will open the empty one, leaving the prize door closed. Therefore, if the player misses and then switches, s/he is certain to get the prize. Summing up, if s/he does not switch the chance of winning is 1/3 whereas if s/he does switch the chance of winning is 2/3. Hard to believe,chance of winning is 1/3 whereas if s/he does switch the chance of winning is 2/3....
View Full Document
This note was uploaded on 09/04/2011 for the course CS 1132 at Cornell.