Let's Make A Deal

Modules - CSE1110, CSE1120 (potentially CSE2110, CSE2120)

 

Teacher’s Notes:

=======================================

I have made this assignment for students in beginning grade 10 computer science but it could easily be modified to work with arrays and or methods.  

This problem is based off of the famous Monty Haul problem.  It is actually a very interesting talking point where you can point out how the reality of a situation is often contrary to our intuitions.  This could be a good discussion about the importance of understanding a problem before we engage in the problem solving cycle.
 

Assignment:

=======================================

 

Let’s Make A Deal

In the game show “Let’s Make A Deal”, the final contestant is shown three doors.  Behind one of the doors is a valuable prize.  There are no prizes behind the other two doors. The contestant is then asked to pick one of the doors and they keep the prize behind that door.  If they choose a door that has no prize behind it, they get nothing.  

 

Before the chosen door is opened however, the host of the show opens one of the other, unpicked doors.  The door that is revealed in this way always has no prize behind it (The host will never reveal the door with the prize behind it).  At this point, the contestant knows that the prize is either behind the door they chose or behind the remaining door that the host did not open.  The host then asks the contestant if they would like to switch doors.  Whether or not they choose to switch, the one they have chosen is opened and they get the prize (or no prize) behind that door.  

 

The questions you are tasked to answer are:

  1. Should the person switch doors?  

  2. Does it matter?  If so, why do you think it matters?

 

To answer these questions, you will write a program that simulates this situation.  Create a program that instantiates an integer variable to represent the door that contains the prize. This variable will be randomly set to be either 1,2, or 3.  

 

Create an integer variable representing the door that the contestant has chosen and randomly assign it to 1, 2, or 3 - representing the contestant choosing their door.  Create another integer variable representing the door the host opens.  You will need to write an algorithm to set this variable so that (a) it is not the same as the door the contestant chose and (b) it does not coincide with the door that contains the prize.  

 

Part 1:

Loop the program to run 1000 times and track how many times the player wins if they do not change their door.  How many times did they win?

 

Part 2:

Loop the program to run 1000 times but in each case, have the player change their choice to the other door that was not opened by the host.  Track how many times they win.  How many times did they win?

 

Part 3:

Answer the questions above.  Should the contestant switch doors?  Did it matter and if so, why do you think it matters?

 

 

 

Solution (JAVA):

=======================================


public class Game {
    public static void main(String[] args) {
        
// PART 1
/*        
        int winCount = 0;
        
        for(int x = 0; x < 1000; x++) {
            int prizeDoor  = (int)(Math.random()*3+1);
            
            int contestantDoor = (int)(Math.random()*3+1);
            
            int hostDoor = 0;
            
            do {
                hostDoor = (int)(Math.random()*3+1);
            }while(hostDoor == contestantDoor || hostDoor == prizeDoor);
            
            if(contestantDoor == prizeDoor)
                winCount++;
        }
        
        System.out.println(winCount);
*/    
        //PART 2
/*        int winCount = 0;
        
        for(int x = 0; x < 1000; x++) {
            int prizeDoor = (int)(Math.random()*3+1);
            
            int contestantDoor = (int)(Math.random()*3+1);
            
            int hostDoor = 0;
            
            do {
                hostDoor = (int)(Math.random()*3+1);
            }while(hostDoor == contestantDoor || hostDoor == prizeDoor);
            
            int originalDoor = contestantDoor;
            while(contestantDoor == originalDoor || contestantDoor == hostDoor)
                contestantDoor = (int)(Math.random()*3+1);
    */        
            /*Alternate way of switching doors
            if(contestantDoor == 1 && hostDoor == 2)
                contestantDoor = 3;
            else if(contestantDoor == 1 && hostDoor == 3)
                contestantDoor = 2;
            else if(contestantDoor == 2 && hostDoor == 3)
                contestantDoor = 1;
            else if(contestantDoor == 2 && hostDoor == 1)
                contestantDoor = 3;
            else if(contestantDoor == 3 && hostDoor == 1)
                contestantDoor = 2;
            else 
                contestantDoor = 1;
            */
/*            
            if(contestantDoor == prizeDoor)
                winCount++;
        }
        
        System.out.println(winCount);    
*/        
    }
}