Skip to content

Monte Carlo simulation for the Monty Hall problem, calculates the probabilities of winning by holding on to original choice, or altering choice.

License

Notifications You must be signed in to change notification settings

abdolrezat/Monte-Carlo-Monty-Hall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Monty-Hall Monte Carlo Simulation MATLAB

Basic Problem Overview

This is the basic definition of the Monty Hall problem:

Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?

How it works

Here, the Monty Hall problem is solved by Monte Carlo simulation, the code eventually calculates the probabilities of winning by either holding on to original choice, or altering choice. If you're new to the Monty Hall problem, see this link for more information. This code can also calculate the problem with any given number of doors and any number of opened doors by the host, as illustrated in the examples in the previous link.

In this approach, the game is played countless times and the history of whether the original choice or the alternate choice were correct is recorded. In the end, the numbers are used to calculate probabilities of winning in both cases. Since every game is simulated with random choices and answers, we'd expect to get a near valid result.

Running the tests

MATLAB is required in order to run the scripts, works with all versions of MATLAB.

The Basic Monty Hall Game

If you want to run the default game (3 doors, 1 uncovered by the host), simply run the script:

sample_play

You may adjust the number of total Monte Carlo iterations in the script. More iterations means better accuracy, but will take longer to finish simulation.

Ideally, the results should be like this:

probability of winning with the first choice: %33.30
probability of winning by altering choice: %66.70

This means that if the player changes his choice after the host opens another door, he'll have twice the chance to win.

Try new things

You can also run the 100 door example in order to get a better understanding of how it works, you'll need to modify the following parameters in the sample script:

n_door = 100; % 100 doors in total
n_doors_uncovered = 98; 

You'll get results similar to this which should add up to 100% :

probability of winning with the first choice: %1.00
probability of winning by altering choice: %99.00

Enjoy.

License

This project is licensed under the MIT License - Author: Abdolreza Taheri

About

Monte Carlo simulation for the Monty Hall problem, calculates the probabilities of winning by holding on to original choice, or altering choice.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages