| Yes you are correct. Corrected simulation gives 50/50 when Monty picks at random among 3 doors. switchWins=33044 switchLoses=33581 #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h> #define NUM_RUNS 100000
#define NUM_DOORS 3
int main(int argc, const char* argv[]) {
srand(time(NULL));
char doors[NUM_DOORS];
int switchLoses = 0;
int switchWins = 0;
for(int i = 0; i < NUM_RUNS; i++) {
memset(&doors, 0, sizeof(doors));
doors[rand() % NUM_DOORS] = 1;
int myPick = rand() % NUM_DOORS;
int montysPick = rand() % (NUM_DOORS - 1);
if(montysPick >= myPick)
montysPick++;
if(doors[montysPick])
continue;
if(doors[myPick])
switchLoses++;
else
switchWins++;
}
printf("switchWins=%d switchLoses=%d\n", switchWins, switchLoses);
return 0;
} EDITED TO ADD: Just for further info: 3 doors: switchWins=33111 switchLoses=33470 4 doors: switchWins=50182 switchLoses=24698 8 doors: switchWins=74876 switchLoses=12687 100000 doors: switchWins=99998 switchLoses=2 |