8
1
I've never been able to wrap my head around the Monty Hall problem. Here's the premise:
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?
Run 10,000 simulations. Output the win percentage of switching. For example:
> 66.66733%
I had trouble with the Monty Hall problem. The point is indeed that Monty Hall only selects doors which do not hide a car. I got the reasoning once I made the same reasoning with 100 doors, 1 car. You choose a door. 1% of the cases you’re right, 99% wrong. If you’re wrong (99%), then Monty opens the 98 doors, the 99 always hide the car; switching is always right. If you’re right (1%), Monty opens 98 doors at random. Not switching is always right. So, in 99% of the cases, switching is right; in 1% not switching is right. You should probably switch. – Édouard – 2016-05-04T19:06:31.853
5The host knows where the car is, so he never opens a door with the car behind it – bendytree – 2013-09-30T21:19:30.820
6As the challenge stands, it's hard to argue that it's not perfectly legal to just have 10,000 runs of the random-number generator and adds up which ones land below 0.6666. You might say that it's not really simulating the Monty Hall problem. But if it produces the exact same output, then what's really missing? – breadbox – 2013-10-01T00:32:51.547
An interesting historical perspective (on the problem, not the golfing): Which Door Has the Cadillac?.
– Cary Swoveland – 2013-10-01T22:29:10.6473The challenge is still a little ambiguous with regards to what assumptions we're allowed to make. For example, some of the answers are probably saving a significant amount of code by assuming the car will be behind the same door every time or the player picks the same door every time. – Iszi – 2013-10-25T19:09:15.263
I took first trying 50 cycles each way in real life and then getting him to code such a simulation himself to convince a friend that switching is the right thing to do. – dmckee --- ex-moderator kitten – 2013-10-30T02:27:35.560
@dmckee I started coding a simulation of it way back in grade 11 when I learned Visual Basic. I was trying to convince my dad about this problem, and as programming it I started optimizing pieces of code you REALLY start to realise that this is in fact true. Coding this yourself is the best way to convince yourself of this problem. – Cruncher – 2013-11-20T20:17:31.353
Also, you can never get a result of
66.66733%
with exactly 10,000 simulations. :P – Joe Z. – 2013-11-20T20:26:37.6271Enumerating all the possibilities is at least as illuminating as generating them randomly... – Daniel Cristofani – 2013-11-20T22:03:51.577