Skip to main content

The Monty Hall Problem

The Monty Hall problem is a probabilistic puzzle that confounds lots of people including a Nobel laurate in physics apparently!

The Monty Hall problem is based on a TV quiz show and is stated in this way: A player is presented with three doors and behind one of the doors is a prize. The aim of the game is for the player to select the door with the prize behind. Of course, the player does not know which of the doors the prize is behind.  The player guesses which of the three doors the prize is behind. At that point one of the doors which the prize is not behind and which has not been selected by the player is opened. So now there are two closed doors. The player is then asked whether they wish to stick with the door that they selected or switch to the other remaining closed door.

Intuitively we think of the problem like this.  Originally there is a one in three chance of us selecting the correct door.  Then one of the doors is opened and then it appears the problem becomes a fifty-fifty choice between the two remaining closed doors so it does not matter whether we switch or not. But this thinking is incorrect.  The answer is the player should always switch because they have twice the chance of winning the prize than if they stick to the door they chose originally.

There are lots of mathematical solutions that demonstrate this on the web. Here we show a solution using a simple program.  IF you run the code below you will find that two thirds of the time you will win the prize if you switch, but if you stick you will win the prize on one in three occasions. Running the code reveals to us what intuitively we cannot see.

Further Reading
https://en.wikipedia.org/wiki/Monty_Hall_problem



Code


import random

correct_swap=0
correct_stick=0
SAMPLES=1000000


# run lots of times so we have a statistically valid result 
for i in range(SAMPLES):

# select a random door for the prize to be behind
 door=random.randint(1,3)

# player makes a selection; 
 player=random.randint(1,3)

# Open a door that neither has the prize behind
# and has not been selected by the player

 open_door=random.randint(1,3)
 while open_door==door or open_door==player:
  open_door=random.randint(1,3)

# Choose whether to stick or switch
 option=random.choice(['stick','swap'])

# stick with the same door
 if option=="stick":
  if door==player:
   correct_stick=correct_stick+1
  else:
   correct_swap=correct_swap+1

# swap door
 elif option=="swap":
  # switch to the other unopened door
  if open_door==1 and player==2: player=3
  elif open_door==1 and player==3: player=2
  elif open_door==2 and player==1: player=3
  elif open_door==2 and player==3: player=1
  elif open_door==3 and player==2: player=1
  elif open_door==3 and player==1: player=2

 if door==player:
  correct_swap=correct_swap+1
 else:
  correct_stick=correct_stick+1

print("Stick: ", correct_stick/SAMPLES*100)
print("Swap:", correct_swap/SAMPLES*100)

Comments

Popular posts from this blog

Mango Learning

We are a community of teachers that have developed extensive computing resources primarily aimed at the English secondary school curriculum that can be accessed here: www.mangolearning.academy .  Mango learning empowers teachers to deliver great lessons that explain complex ideas using clear and highly scaffolded teaching and learning resources. We are very excited to offer these resources for free to the community. These teaching and learning resources for computing are made by teachers for teachers and we understand the day-to-day challenges that teacher face.   The resources incorporate general and computing specific evidence-based pedagogy. We incorporated spaced retrieval practice though knowledge organisers, diagnostic questions and quizzes, for instance. We also incorporate ideas from cognitive load theory through lots of worked examples.   To help with coding we use PRIMM and block to text based pedagogical approaches.   To support literacy we address ...

Teaching Children to Read Code using Evidence-based Approaches

Before students can write code, they need to be able to read code. Computer science pedagogy is often based around the ideas of Piaget’s constructivism - where pupils develop their knowledge through exploration, and Papert’s constructionism - where pupils learn through creating artifacts. However, evidence has shown that learners need guidance to gain useful knowledge efficiently and to organise that knowledge in a clear and logical way. They need to be able to break a problem down, remove the unnecessary detail, find patterns and think algorithmically before they can start to write programs for solving problems. Just as we wouldn’t expect a young child to write prose before they can read, we need to provide guided approaches that use direct instruction and scaffolding to help our students read code before they can be expected to write code themselves. These guided approaches are needed just as much as, if not more than, creative discovery activities. Explain the code My first approach...

Automatic Marking and Grading

While teaching is wonderful, worthwhile and rewarding it is a highly demanding and stressful profession.  So it is little surprise that there is  high rate of staff turnover with nearly o ne in 10 teachers are leaving the teaching profession in English schools each year citing burnout, overwork and stress as the principal reasons (Department for Education). To improve teacher retention a better work life balance is needed. In fact, reducing high workload was one of the motivations for the industrial action of 2023 by the NEU.  One area where large improvements can be made in work-life balance is the marking of student work. Teachers spend 9 hours per week marking student work (EEF, 2016) and if any reductions can be achieved in this area then we can go a long way to improving working conditions for teachers.  Some efforts have been made to automate grading using for instance self-marking online multiple-choice tools like  www.diagnosticquestions.com  or Mic...