I mentioned that I was going to try to program a Monty Hall Problem simulator in my post yesterday entitled Losing My Marbles well it turns out that this is REALLY lame. Why? Well it is simple, there really isn’t much to it once you know the mechanics.
Pseudo Code:
Testing “always switch”:
- Pick a random number >= 1, <= 3. This is the door# where the car is hidden. Call this CarBehindDoor.
- Pick a random number >= 1, <= 3. This is the door# the contestant picked. Call this ContestantChoiceDoor.
- if CarBehindDoor = ContestantChoiceDoor then the contestant loses and we add one to LossCount.
- If CarBehindDoor != ContestantChoiceDoor then the contestant wins and we add one to WinCount.
- Go back to 1 (loop).
Testing “always stay”:
- Pick a random number >= 1, <= 3. This is the door# where the car is hidden. Call this CarBehindDoor.
- Pick a random number >= 1, <= 3. This is the door# the contestant picked. Call this ContestantChoiceDoor.
- if CarBehindDoor = ContestantChoiceDoor then the contestant wins and we add one to WinCount.
- If CarBehindDoor != ContestantChoiceDoor then the contestant loses and we add one to LossCount.
- Go back to 1 (loop).
Once this is written… it is painfully obvious that “Always Stay” results in a win 33% of the time and that “Always Switch” results in a win 66% of the time. *sigh* and I thought this would be a fun thing to write.
On a sad note I still wrote the test application and here are the results of a run of 100 million tests of “Always Switch”:
Wins: 66,667,053 Losses: 33,332,947