Probability teaser 1 – the Monty Hall problem

Introduction

I recently posted the following teaser on Twitter:

Self-doubt

This is known as the Monty Hall problem, named after the game show host.

When I first read this problem, my brain initially told me that my chances were 50/50, whether I stuck with my first door or switched to the only other closed door. Of course, I’m a bit of a natural sceptic and so I had this niggle in my head that said 50/50 was too obvious. So off I went to read up on the problem.

A number of people responded to my tweet. Most thought it was also a 50/50 chance even when I tried, in a limited stutter of 280 characters, to explain the real answer. One person said it would be higher than 50/50 but they couldn’t remember the maths and only one person gave the correct answer, so let’s see if we can get there together.

Breaking it down

Let’s begin with just three doors.

? ? ?

One door has a car behind it, the other two have goats. Your chances of picking the car is 1 in 3, 1/3, 33.3% to use various measures. I will use a probability measure of 0.33… which is on a scale of 0-1. If you add up all the probabilities of events that can happen, they will add up to one. You can only pick the car or a goat. There are no other options. Therefore, the chances of picking a goat are 2/3, or 0.66…. This can be calculated as 1-0.33…

(Note, for numbers that are recurring, I am using two decimal places with the … notation)

The doors can be setup before the game as below, G=goat, C=car:

GGC

GCG

CGG

Remember what happens when you pick your door? Monty will open all but one of the other doors to reveal a goat, so you end up with your chosen door and one unopened door. So one of two situations can happen here.

  1. You pick the car 1/3 of the time and the other door will always be a goat
  2. You pick a goat 2/3 of the time and the other door will always be the car

The teaser asks, what is your chance of winning the car if you switch doors. Therefore, 1/3 of the time when you switch, you lose (or win if you prefer goats) and 2/3 of the time when you switch, you will always get the car. So no 50/50 here.

It gets better

OK, the last section started with the basics using just 3 doors, but my question was with a game using 10 doors. Let’s use the same process but update the numbers accordingly.

? ? ? ? ? ? ? ? ? ?

One door has a car behind it, the other nine have goats. Your chances of picking the car is 1 in 10, 1/10, 10% to use various measures. I will use a probability measure of 0.1 which is on a scale of 0-1. If you add up all the probabilities of events that can happen, they will add up to one. You can only pick the car or a goat. There are no other options. Therefore, the chances of picking a goat are 9/10, or 0.9. This can be calculated as 1-0.1.

Remember what happens when you pick your door? Monty will open all but one of the other doors to reveal a goat, so you end up with your chosen door and one unopened door. So one of two situations can happen here.

  1. You pick the car 1/10 of the time and the other door will always be a goat
  2. You pick a goat 9/10 of the time and the other door will always be the car

The teaser asks, what is your chance of winning the car if you switch doors. Therefore, 1/10 of the time when you switch, you lose (or win if you prefer goats) and 9/10 of the time when you switch, you will always get the car.

So…always, always switch!

Still not convinced?

OK, sometimes people like to see this in action and so I’ve created a Python script here that simulates the game. Please don’t troll me too much for the lack of Pythonic code, although I welcome constructive feedback! Hopefully the code is commented well enough for you to see what it is doing.

Summary

I’ve always loved probability and statistical type problems because they are great examples of using pure mathematics to challenge people’s assumptions and biases. Hopefully, you found this example clear. If not, let me know so I can improve upon it.

Till the next time.

Getting started with coding – Part 7 – Next Steps

Introduction

In part 6, we looked at a number of training options to help take your knowledge and skills to another level.

In this final part of my Getting Started With Coding series, we will review what we’ve covered so far and then try to answer the question that will, at some point, inevitably crop up. “What do I do next?”. Continue reading “Getting started with coding – Part 7 – Next Steps”

Getting started with coding – Part 5 – Version control

Introduction

In part 4, we discussed some additional tools to help your coding. In part 5, we look at version control, which is a way of tracking changes you make to your code (or in a wider sense, documents, information, etc.). As it is such an important topic, I think it warranted its own post, even though technically it is just another tool in your kit. Continue reading “Getting started with coding – Part 5 – Version control”

Getting started with coding – Part 3 – Editors

Introduction

So you want to start following examples you’ve found online or in a book to learn more about your chosen language from part 2. Which editors should you consider to start knocking up some super useful scripts? Part 3 looks at three broad categories, giving some suggestions along the way. Continue reading “Getting started with coding – Part 3 – Editors”

Getting started with coding – Part 2 – Languages

Introduction

In part 1 of this series, we addressed the key concerns people starting to code might have and also set out some key reasons why you should give it a go in spite of those, often unfounded, concerns. In part 2, we cover off how to go about picking one of the languages to learn to code in from the numerous choices. Continue reading “Getting started with coding – Part 2 – Languages”

Getting started with coding – Part 1 – Introduction

Introduction

If you work with computers in any aspect of your life, being able to code can be a very powerful tool. All too often however, I hear people say things like “it’s too difficult” or “I’m not a developer” and they never take more than their first few steps. This post, the first in a series on getting started with coding, addresses both the fears of taking your first steps and the benefits of starting that journey. The remaining posts then give you all the help you need to overcome those perceived obstacles and have some fun along the way. Continue reading “Getting started with coding – Part 1 – Introduction”