Computer Science Canada Simulating the Monty Hall problem |
Author: | CaptainShrimps [ Sun Apr 28, 2013 9:43 am ] | ||
Post subject: | Simulating the Monty Hall problem | ||
I wrote a program to simulate the Monty Hall problem to show my dad that the odds are only 50/50 if you randomly choose to stay with your original choice or switch to the other door. He said my code was wrong, so I'm posting it here to see what everyone thinks.
|
Author: | evildaddy911 [ Sun Apr 28, 2013 11:11 am ] |
Post subject: | RE:Simulating the Monty Hall problem |
the output IS accurate. * when you switch the chance of being right is 2 in 3 * when you stay, the chance of being right drops to 1 in 3 * if you randomly choose stay or switch, the chance should be the the average of the 2 options, making the chance 1.5 in 3, or 1 in 2 |
Author: | nullptr [ Wed May 01, 2013 10:42 pm ] |
Post subject: | Re: Simulating the Monty Hall problem |
The Monty Hall problem is one of those problems that seems so much a common-sense question that people will very stubbornly defend their answers. Good luck convincing your dad -- your code looks good to me. |
Author: | DemonWasp [ Thu May 02, 2013 12:13 am ] | ||
Post subject: | RE:Simulating the Monty Hall problem | ||
In general, shorter code is easier to prove correct (or at least assure yourself it is correct). Here's my take on the code, which displays each individual trial. Even with trials = 20, the pattern is very likely to be obvious:
The other argument you could use is this: 1. You have a 1-in-3 chance of choosing correctly at first. 2. If you chose correctly (1 in 3), then staying wins 100% of the time but switching loses 100% of the time. 3. If you chose incorrectly (2 in 3), then switching wins 100% of the time but staying loses 100% of the time. Because case #2 has only a 1-in-3 chance of occurring, staying only wins in 1-in-3 cases. |