News

My Stats

  • Posts - 305
  • Comments - 223
  • Trackbacks - 82

Twitter












Tag Cloud


Recent Comments


Recent Posts


Article Categories


Archives


Post Categories


Entertainment


Friends


Tech/Geek



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”:

  1. Pick a random number >= 1, <= 3. This is the door# where the car is hidden. Call this CarBehindDoor.
  2. Pick a random number >= 1, <= 3. This is the door# the contestant picked. Call this ContestantChoiceDoor.
  3. if CarBehindDoor = ContestantChoiceDoor then the contestant loses and we add one to LossCount.
  4. If CarBehindDoor != ContestantChoiceDoor then the contestant wins and we add one to WinCount.
  5. Go back to 1 (loop).

Testing “always stay”:

  1. Pick a random number >= 1, <= 3. This is the door# where the car is hidden. Call this CarBehindDoor.
  2. Pick a random number >= 1, <= 3. This is the door# the contestant picked. Call this ContestantChoiceDoor.
  3. if CarBehindDoor = ContestantChoiceDoor then the contestant wins and we add one to WinCount.
  4. If CarBehindDoor != ContestantChoiceDoor then the contestant loses and we add one to LossCount.
  5. 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


posted @ Friday, June 26, 2009 7:22 AM | Filed Under [ Personal ]

Comments

Gravatar # re: Programming a Monty Hall Simulator
Posted by Bill on 6/26/2009 11:03 PM
We must be geeks.

I understood the logic (key = Monty Knows (and shows!) the answer and always picks a non-winner)after reading the Coding Horror blog post, but did the same thing as you (wrote a simulator).

More fun than a proof with equations!

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: