Turns out that choosing the other door is indeed 66%. While choosing your door is 33%.
Pretty significant difference.
Other interesting results is that if there are four total doors choosing the "other" door goes from 25% (1/4) to ~37%.
with ten doors it goes from something like 10% to 11%...
If anyone cares to nerd out, the following is a .c program and can be compiled with gcc and ran.
pass it a "1" option and you'll choose the "other" door..
<pre>
#include "stdlib.h"
#define NUM_DOORS 3
#define PASSES 100000
static int gs_iLosses;
static int gs_iWins;
static int gs_iChooseOtherDoor;
int main(int argc, char *argv[])
{
// if 1 is passed as argument then we'll choose the "other" door.
if(argc > 1 && atoi(argv[1]) == 1) {
printf("Choosing the OTHER door....\n");
gs_iChooseOtherDoor = 1;
} else {
printf("Sticking with OUR door...\n");
gs_iChooseOtherDoor = 0;
}
// random seed
unsigned int iseed = (unsigned int)time(NULL);
srand(iseed);
gs_iLosses = 0;
gs_iWins = 0;
int i = 0;
for(i = 0; i < PASSES; i++) {
if(SelectDoor() == 1) {
gs_iWins++;
} else {
gs_iLosses++;
}
}
printf("Wins:%d\n",gs_iWins);
printf("Losses:%d\n",gs_iLosses);
printf("(%ld%% Wins)\n",(gs_iWins*100)/PASSES);
return 0;
}
int SelectDoor() {
// now get one winner door. THIS CAN BE ANYTHING.
int iWinnerIdx = getRandomIndex(NUM_DOORS);
// now select OUR random door. THIS CAN BE ANYTHING.
int iSelectedDoorIdx = getRandomIndex(NUM_DOORS);
// now let's get the door which ISN'T the winner and ISN'T our door.
// This is the one we see and will NOT CHOOSE BECASE ITS A LOSER.
int iLosingNonSelectedDoorIdx = getRandomIndex(NUM_DOORS);
while((iLosingNonSelectedDoorIdx == iSelectedDoorIdx) ||
(iLosingNonSelectedDoorIdx == iWinnerIdx)) {
iLosingNonSelectedDoorIdx = getRandomIndex(NUM_DOORS);
}
if(gs_iChooseOtherDoor) {
// now let's select the unselected door (aka "Other door")...
// We don't care about winner idx, we just want NOT our door and NOT the loser door...
int iNewSelectedDoorIdx = getRandomIndex(NUM_DOORS);
while((iNewSelectedDoorIdx == iSelectedDoorIdx) ||
iNewSelectedDoorIdx == iLosingNonSelectedDoorIdx) {
iNewSelectedDoorIdx = getRandomIndex(NUM_DOORS);
}
iSelectedDoorIdx = iNewSelectedDoorIdx;
}
// Now Let's see if we won!!!
if(iSelectedDoorIdx == iWinnerIdx) {
return 1;
}
return 0;
}
// random number 0-n
int getRandomIndex(int _iMax) {
int iRand = rand();
return iRand/(int)(((unsigned)RAND_MAX + 1) / _iMax);
}
</pre>
Edited 2 time(s). Last edit at 03/31/2009 02:13PM by Jib.