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 vocabulary head on, enco

Semantic Waves

In the previous post we looked at the transfer of learning from block based coding to text based languages.  Semantic waves offer a theory that help us to structure our lessons to support transfer of learning (Maton, Waite et al).  When we present concrete examples in single contexts transfer of learning is going to be weak.  We need to present multiple examples in a range of context.  This allows us to abstract out the underlaying features.  This idea of moving along a continuum between the abstract and concrete is given by the term semantic gravity.  For instance, if we talk about an algorithm in abstract terms we might say that it is a sequence of steps to solve a problem.  At this stage we have presented it as an abstract idea so has low semantic garvity.  In a lesson we might then go on and write algorithms for drawing squares.  This represents a concrete episode with high semantic gravity.  In a good lesson we might also want to give multiple examples of algorithm in different co

How to support your students to write code

For many children writing code can be a daunting prospect. To help children learn to write code more easily we can use a range of scaffolded pedagogies. Initially these approaches take ownership of the code away from the students thereby giving them confidence to explore and experiment with the code.   Gradually as the students learn more and more we can reduce the amount of support until they are able to write their own programs independently.   In a previous article we looked at approaches for supporting pupils to learn to read code that included activities such as explaining, predicting and tracing code, and live demonstrations with worked examples. This follow up article presents some approaches to support pupils with writing code. Fixing broken code Children can find and fix common syntax, runtime and logical errors in a piece of code. Errors might include missing brackets, missing speech marks, spelling mistakes and missing variables declarations, for instance. The pupils