Skip to content

tjakway/monty_hall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simulates the Monty Hall Paradox.  From wikipedia (http://en.wikipedia.org/wiki/Monty_Hall_problem#The_paradox):

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? (Whitaker, 1990, as quoted by vos Savant 1990a)

The paradox is that, intuitively, switch doors should not matter and you should have the same chance of winning a car regardless of what you do.  In reality, not switching gives you the correct answer only 33% of the time and switching makes you win 66% of the time.

Uses ISAAC (public domain) for random number generation.  See http://burtleburtle.net/bob/rand/isaacafa.html.

DEPENDENCIES:
cmake >2.8 to build
(ISAAC is in included as source files in include/ and src/, no installation necessary)

BUILDING:

(NOTE: only builds for x86 (32 bit) because ISAAC only typedefs its values--it's not really platform independent.  Get ISAAC64 and change the ISAAC calls to the appropriate ISAAC64 to build for x86-64)

mkdir bin
cd bin
cmake -GUnix\ Makefiles -DCMAKE_BUILD_TYPE=RELEASE ..
make
./monty_hall_simulator

Tested on Linux (Ubuntu 14.10) and Mac

EXAMPLE OUTPUT:

Running the simulator the default number of times (2000000).  Pass --count <number> to run the simulation <number> of times, first with the player switching doors, then without.

**********MONTY HALL SIMULATION RESULTS**********
The player chose TO switch.
COUNT = 2000000 (number of times the simulation was run)
NUM_SUCCESS = 1333995
NUM_FAILURE = 666005
Percent correct guesses (GOT THE CAR): 0.666998
Percent incorrect guesses (GOT THE GOAT): 0.333002

*************************************************
The player chose NOT to switch.
COUNT = 2000000 (number of times the simulation was run)
NUM_SUCCESS = 666566
NUM_FAILURE = 1333434
Percent correct guesses (GOT THE CAR): 0.333283
Percent incorrect guesses (GOT THE GOAT): 0.666717

About

A simple simulation of the Monty Hall Paradox in C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published