3 ms·
I wrote a simulation as an exercise (not to convince myself, just to illuminate the logic). I recall becoming extra-convinced when I spotted an optimization tha
by 0xcde4c3db 8y ago
I wrote a simulation as an exercise (not to convince myself, just to illuminate the logic). I recall becoming extra-convinced when I spotted an optimization that would have been paradoxical if the correct solution hadn't been correct. I don't remember exactly what it was; I think it had something to do with collapsing nested if() into a single if() based on p vs. (1 - p) for the original door choice.
edit: the more I think about it, the more I suspect that the actual optimization was not randomizing both the door choice and the location of the car, which then allowed simplifying the win logic. If door 0 is always considered the door with the car, then the whole loop body can be collapsed down to:
if (rand() / (RAND_MAX / 3) == 0) noswitch_wins++;
No threat of a paradox as I was thinking before, but a fairly clear statement that the odds of winning by not switching are 1 in 3.