One of my friends here in Australia left ‘The Curious Incident of the Dog in the Night-Time’ at our house. So I started to read it and have finished reading it and it is excellent!
Anyway there’s a point in the book where they talk about The Monty Hall Problem (see the link for information), my flat mate Andy does not believe changing matters. So I have written a little program in C# .NET that tries to prove The Monty Hall Problem. Here it is, although the results really seem to prove absolutely nothing -
Random r=new Random(); bool change=true; int correctChange=0; int correctNoChange=0; int maxLoop=100000000; for(int x=0;x<maxLoop;x++) { int correctAnswer=r.Next(3); int guess=r.Next(3); int showDoor=0; showDoor=correctAnswer%2 + 1; correctNoChange+=(guess==correctAnswer)?1:0; guess=((showDoor+correctAnswer)%2)+1; correctChange+=(guess==correctAnswer)?1:0; }
I ran this 10,000,000,000 times and the difference on changing was 161026.











There’s something wrong in your code with all those modulus operators. Or in
your assumptions. I have a working version but your comment filter won’t let me post it because it thinks it is spam. Trying one last time with a different email address.
Sorry about the incorrect indentation but your comment filter thinks it is spam with the necessary nonbreaking spaces in it.
This somewhat more simplistic version gives the correct result:
static void Main(string[] args)
{
int games = (args.Length > 0 ? Convert.ToInt32(args[0]) : 10000);
Random r = new Random();
int correctWhenStick = 0;
int correctWhenChange = 0;
for (int i = 0; i < games; i++)
{
int rightAnswer = r.Next(3);
int initialGuess = r.Next(3);
if (initialGuess != rightAnswer)
{
// your initial guess is wrong
// the other booby prize door is open
// so to change is to get the prize.
correctWhenChange++;
}
else if (initialGuess == rightAnswer)
{
// you got the prize right first time.
// so to stick is to get the prize.
correctWhenStick++;
}
}
Console.WriteLine(“Over ” + games + ” games, changing wins ”
+ correctWhenChange + ” times and sticking wins ” + correctWhenStick
+ ” times.”);
}
Comment by Thomas David Baker — March 17, 2005 @ 8:51 pm
There’s something wrong in your logic. I’ve written a more simplistic version that gives the correct results here: http://bluebones.net/montyhall.txt
PS Your spam filter is driving me nuts. This is attempt number 7 to post this.
Comment by Thomas David Baker — March 17, 2005 @ 8:55 pm
tried to comment. can’t get passed your filters.
Comment by t — March 20, 2005 @ 8:09 pm
slot blot assay
Slot blot assay. The M…
Trackback by slot blot assay. Maryann Geronim — April 23, 2006 @ 6:50 am
slot blot assay
Slot blot assay. The M…
Trackback by slot blot assay. Maryann Geronim — April 23, 2006 @ 6:50 am