Monty Hall problem - PHP
This evening, after returning from an excellent VBUG: Brighton (of which more in a later post), Richard was talking about the Monty Hall problem after listening to a discussion about it on the BBC podcast In Our Time.
For those who don't know the Monty Hall problem it is this:- A gameshow set has 3 doors.
- Behind one of the doors is a prize.
- Behind the other 2 doors is nothing.
- The contestant choses a door.
- The gameshow hosts, knowing where the prize is, and which door the contestant has chosen, opens a door which he knows hasn't got the prize behind it and the contestant hasn't chosen.
- The contestant is then offered the opportunity to trade their door for the one remaining door.
Should the contestant switch? The answer is yes 2/3rds of the time. See here for the reasons.
Richard and I both set about proving it in the tools we had available, I chose PHP, Richard chose Scala. And we both can successfully demonstrate that by always switching doors the contestant is more likely to win.My PHP version is downloadable here.