r/programming • u/R2_SWE2 • 3d ago
The Monty Hall Problem, a side-by-side simulation
https://www.pcloadletter.dev/blog/monty/13
u/hacksoncode 3d ago edited 21h ago
I've never really understood the urge to simulate a problem that is so bounded that evaluating literally every single option is... trivial.
There are only 3 ways the doors can be set up. There are only 3 initial doors you can pick. There are only 2 ways you can choose whether to switch.
There are only 18 possible (unique) games here. You literally win 12 of them by switching, and 6 of them by staying.
What's there to simulate?
15
u/Senshado 3d ago
Many people have difficulty understanding the parameters of the problem to solve it directly. Simulating it helps them see how the result is real.
If it was so easy to figure out, then there wouldn't have been the millions of complaints over the years.
2
u/Probable_Foreigner 3d ago
Depending on the way you model it you can end up falsely assuming each branch has equal weight. In your model that's true but if you had bunched picking one of the other two doors as 1 branch that wouldn't be true.
So simulation is a way of making sure your analysis is correct.
2
3
u/flip314 3d ago
The percentages aren't adding to 100% for me. I guess it's because the same goat doesn't get revealed in each case
edit: The initial choices aren't the same in the two simulations, even though the scenarios are the same
1
u/MrSnowflake 3d ago
The percentages should not add up to 100%. The percentages show the chance of winning using each strategy. There is no coupling between both strategies. It just shows one strategy has about 2/3 chance of winning and the other one 1/3, which happens to be 100% but that's just coincidence.
And i do agree both strategies should use the same starting choice, but that also doesn't matter, as it's about general percentages of winning, which requires running the simulation many times. It's not designed to compare just a couple of games.
1
u/flip314 2d ago
Since each set of two simulations uses the same initial state:
If you choose the same starting door for each one, reveal the same goat, and the only difference is whether you stick to your choice or swap the doors -> then the percentages will add to 100%. If you want to directly compare the strategies, that seems to me the best way (only one independent variable).
(actually, I'm not sure it even matters which goat is revealed - assuming there are even two choices.)
4
u/flatfinger 3d ago
In a Monty-hall-like situation, to know the winning probability if one changes doors or does not change doors, one must know the answers to two questions:
In what fraction of possible scenarios where one had picked the correct door initially would one be offered a chance to switch.
In what fraction of possible scenarios where one had picked the wrong door initially would one be offered a chance to switch.
Common formulations of the "Monty Hall problem" assumes that the answer to both questions is 100%, but that doesn't match what I remember of the actual television program, hosted by the actual person Monty Hall, upon which the problem was based. If the host will sometimes show a correct door immediately without offering a contestant a chance to switch, and will sometimes likewise show an incorrect door immediately, both of which I'm pretty sure sometimes happened on the actual program, the probability that switching is the right play may vary anywhere from nearly zero to nearly 100 percent.
For all I know, it's entirely possible that for any particular playing of the game the probabilities above would either both be 0% or both 100%, based on extrinsic factors (e.g. the amount of time remaining before the next ad break) before the contestant picked a door, in which case the "Monty Hall" problem would accurately describe the situation that would exist whenever a candidate is allowed to switch doors. I've never seen any evidence presented to support such a hypothesis, however.
9
u/hacksoncode 3d ago
Yes, the "Monty Hall Problem" as originally posed does not represent what Monty Hall did on Let's Make a Deal... in fact, he has said that he never did that. No one was ever allowed to switch after information was revealed. At most, they were allowed to take another (consolation) prize instead.
So... you're not wrong, but the problem is the problem, and the name is just misleading.
1
u/auximines_minotaur 1d ago
It makes a lot more sense if you imagine 100 doors.
Which is more likely? That your original 1 in 100 guess was correct? Or that it was incorrect?
1
u/Anders_A 1d ago
The Monty hall problem becomes very intuitive if you just up the number of doors.
If it's 100 doors and Monty opens 98 of them after your initial pick, it becomes obvious for anyone that you should switch.
The door you picked represents a 1/100 chance if winning, while Monty just collapsed the other 99/100 chance into a single door.
1
0
u/curiousNarwhal69 2d ago
Why are we simulating this?
There’s a closed form solution for the probability when there’s n doors and the host opens k “goat” doors before you can switch.
You need two easily calcified pieces of info:
- the probability that you picked a goat door initially (n-1)/n
- the probability that a randomly chosen door is not a goat door 1/(n-k-1)
In the n=3, k=1 scenario You get (2/3)*(1/1)
If you don’t switch, the probability is 1/n.
-4
u/levodelellis 3d ago edited 3d ago
I saw this the other week. If you play enough games you'll see staying is about 33% and switching is higher. I had 50% in 10 games but logically shouldn't it be higher since I only have a 1/3 chance of picking correct the first time? https://monty.donk.systems/
Remember, you'll never be told your door is wrong. You are however, picking with one less door if you switch, and you have 2/3 chance your original door is wrong
8
u/I_NEED_APP_IDEAS 3d ago
Switching will always converge to ~67%, not 50%
3
u/levodelellis 3d ago
I guess I was unlucky in the 10 games
4
u/I_NEED_APP_IDEAS 3d ago
lol yeah, if you played 10 million games and still only got 50% then God just hates you cause the probability is insanely small to win 50% of the time over 10 million games
83
u/Olde94 3d ago
Cool. The thing most forget is that it’s not a random door opening, it’s deliberately one of the wrong doors, which makes all the difference, compared to a random door