Name: Anonymous 2011-08-29 6:51
Someone please tell me why this simulation is producing the same results for swapping and not swapping.
#include <iostream>
#include <algorithm>
#include <ctime>
const int steps = 10000000;
void monty_hall(bool switch_choice)
{
unsigned long long wins = 0;
int doors[3] = { 0, 1, 1 };
int choice, reveal;
for(int i = 0; i < steps; ++i)
{
std::random_shuffle(doors, doors + 3);
choice = rand() % 3;
reveal = rand() % 2;
if(reveal)
reveal = choice + 1;
else
reveal = choice - 1;
if(reveal > 2)
reveal = 0;
else if(reveal < 0)
reveal = 2;
if(switch_choice)
{
if(choice != 0 && reveal != 0)
choice = 0;
else if(choice != 1 && reveal != 1)
choice = 1;
else
choice = 2;
}
if(doors[choice] == 0)
++wins;
}
std::cout << wins;
}
int main()
{
srand(time(NULL));
std::cout << "Not switching: ";
monty_hall(false);
std::cout << "\n\nSwitching: ";
monty_hall(true);
}