It is also a Windows command line program written in very simple C that could easily be ported to Unix/Linux or even MacOS. There were actually only a few changes necessary to create the multi-door program - the whole task took less than an hour. I spent far more time making the command line input user friendly and reworking the help message. The results were right in line with what I expected them to be given my new understanding of the original Monty Hall Paradox.
The source code is here. You can download the source code and executable from here. Below is the help message:
This program runs simulations of the Monty Hall Paradox, for info, see https://en.wikipedia.org/wiki/Monty_Hall_problem Half of the simulations are Keep 1st choice, half are Switch. Output is a running tally of Wins and Loses for both Keep and Switch. Usage: montyhall20.exe {a|k|s|?} {#simulations} where a = alternate between keep & switch each time (default) k = run all keep simulations 1st, then all switch s = run all switch simulations 1st, then all keep ? = print this message and exit. where #simulations >= 200 and <= 10 million (default=2000) with half Keep original choice and half Switch choice. Note: { } are optional args and | means choose only one. Examples: C:>montyhall20.exe -> alternate keep & switch each of 2000 times C:>montyhall20.exe k -> 1000 keep followed by 1000 switch C:>montyhall20.exe s 20000 -> 10000 switch followed by 10000 keep C:>montyhall20.exe 2000000 -> alternate keep & switch 2 million times Program also works with more than 3 doors Usage: montyhall20.exe {a|k|s|?} [#simulations] [#doors] {#show} where [ ] = required, 3 <= #doors <= 100, 1 <= #show <= #doors-2 Examples: C:>montyhall20.exe a 2000 4 2 -> 1000 each keep/switch, 4 doors, show 2 C:>montyhall20.exe 9000 9 -> 4500 each keep/switch, 9 doors, show 1 If output is redirected to a file, fewer running tallies are displayed, and if only 3 doors, the file contains additional info. (However redirecting to nul produces no output at all.)Here is some sample output:
Back to the original paradox
View or Download C source code
Download both the source code and the executable (zip file)
Back to Leigh's Home Page | Site Map | Site Search |