淺談蒙提霍爾博弈問題 - Monty Hall Program

“The Monty Hall problem is a brain teaser, in the form of a probability puzzle, loosely based on the American television game show Let’s Make a Deal and named after its original host, Monty Hall.”

簡易實作

float Solutions::montyHall(int guess)
{
int winningNum = 0;
int switchedNum = 0;
int switchedCount = 0;
int elimNum = 0;
for (int i = 0; i < 1000; ++i) {
winningNum = getRandom(1, 3, 0);
elimNum = getRandom(1, 3, winningNum);
switchedNum = getRandom(1, 3, elimNum);
while (switchedNum == guess ) {
switchedNum = getRandom(1, 3, winningNum);
}
if (switchedNum == winningNum) switchedCount ++;
}
return 100 - (switchedCount / 10);
}

int Solutions::getRandom(int low, int high, int badNum)
{
int random = rand() % high + low;
while ( random == badNum ) {
random = rand() % high + low;
}
return random;
}

Reference

[1] 三們問題

[3] 決勝21點

Thanks for reading! Feel free to leave the comments below or email to me. Any pieces of advice or discussions are always welcome. :)