following problem is sometimes called \"The Monty Hall Game Show Problem\". you
ID: 3766648 • Letter: F
Question
following problem is sometimes called "The Monty Hall Game Show Problem". you are a contestant on a game show and have won a shot at the grand prize. Before you are three closed doors. Behind one door is a brand new car. Behind the other two doors are consolation prizes The location of the prizes is randomly selected. The game show host asks you to select a door, and you pick one. However before revealing the contents behind your door, and you pick one of the other doors with a consolation prize. the name show host asks if you would like to stick with your original Choice or switch your choice to the other dosed door What choice should you make to optimize your chances of winning the car? Does it matte, whether you stick with your original choice or switch doors? Write a simulation program to solve the game show problem. Your program should make 10,000 simulated runs through the problem, randomly selecting locations for the prize-, and then counting the number of times the car was won when sticking with the original choice and counting the number of times won when sticking with the original probability of the car was won when switching simulates the winning for both strategies. Be sure that you not make process of selecting the door, revealing one, simply assuming that assumptions about the actual solution (for example, P there is a 1/3 or 1/2 chance of getting the prize).Explanation / Answer
One door contains a car and the other two contains consolation prizes.
Let A,B,C be the doors.
let you choose door A. The probability of A being the door with the car is 1/3. So, the probabilty of A being not with the car is 2/3. If host reveals a door without the car(Let it be B). There ate two doors left and proability of A being door with the car is 1/3 so, the probability of C being the door with the car is 2/3.
case 1: If you do not switch the doors then probability of winning car is 1/3.
case 2: If you switch the doors then probability of winning car is 2/3.
Code:
#include <bits/stdc++.h>
using namespace std;
int reveal(int c){
int y;
while(true){
y=rand()%3;
if(c!=y){
return y;
}
}
}
int main(){
srand(time(NULL));
int wins=0;
int loss=0;
for(int i=0;i<10000;i++){
int car=rand()%3;
int select=rand()%3;
int r=reveal(car);
//As you switch cars
if(select==car){
loss++;
}
else{
wins++;
}
}
cout<<(wins*1.0)/(10000*1.0)<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.