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 ...

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...

Block to Text Programming

When we move students on from block to text programming, we want to transfer the learning that they have made on block coding into text programming.   When we are transferring learning we want to transfer knowledge from one context into another. In moving from one context to another we need to think in an analogical manner such that when we know how to solve a problem in one domain we can use it to help us solve a problem in another domain. The use of analogous examples helps learners see the deeper structure. We do this by seeking out deep structures and remove the surface structure of a problem. This approach is called expansive framing and we have expectation of future use in a different context. In contrast, bounded framing does not have utility beyond the current learning. Current learning needs to make connections to earlier contexts from which learners are expected to transfer in knowledge to the new context. Transfer of learning does not happen by itself; the teacher ...