The Monty Hall Brainteaser
Dean Esmay posted an interesting brainteaser
which people constantly get wrong. As a followup to this, David Gillies
sent him some C++ code which simulates the problem, to 'prove' what the
correct answer is.
Not to be outdone, I have written a small Perl script which does the same
simulation. You can either check out the code, or just run the simulation
for yourself:
Notes:
- The Perl code is written in an attempt to simplify the logic in the 'main loop'. It uses a routine called 'pick_door' to choose (randomly where possible) a valid door; the concept of this routine is simple, but the actual code takes some understanding!
- Random Numbers. I believe that the random number generator in most Perl engines is pretty good - so I haven't worried about using a special random number generator. Oh, and a 'random' seed is automatically generated when rand() is first called.
David Yule<david at yule dot org>
Last modified: Mon Jan 13 13:05:46 CST 2003