#quiz 몬티 홀 문제(Monty Hall problem)

2 minute read

Suppose you’re on a game show, and you’re given the choice of threedoors: Behind one door is a car; behind the others, goats. You pick adoor, say No. 1, and the host, who knows what’s behind the doors, opensanother door, say No. 3, which has a goat. He then says to you, “Do youwant to pick door No. 2?” Is it to your advantage to switch your choice?

\­ A widely known statement of the problem is from Craig F. Whitaker of Columbia, Maryland in a letter to Marilyn vos Savant’s September 9, 1990, column in Parade Magazine (as quoted by Bohl, Liberatore, and Nydick).

게임 쇼 마지막에 부상을 준다고 한다. 단 꽁짜로 그냥 주지는 않는다. 3개의 문 중에서 하나를 고르라고 하는데, 하나의 문 뒤에는 멋진 차가 있고 나머지 문에는 염소가 있다. 꽁짜로 차를 얻기 위해서 고심을 하다가 하나의 문을 고르게 되는데, 그냥 그 문을 열어주지 않고 사회자가 나머지 2개의 문 중 염소가 있는 하나의 문을 열어주면서 “선택을 바꾸시겠습니까?”라고 물어본다.

딱 확률적으로만 따지만 그냥 처음에 선택한 문을 고집하는게 정답일 확률이 높을까? 아님 사회자가 열지 않은 문을 선택하는게 정답일 확률이 높을까?

결론은 선택을 바꾸었을때 차를 가져갈 확률은 2/3, 바꾸지 않았을 때는 1/3이다. 위키피디아 (영문)에 정말 자세히 설명되어 있다. 그나저나 내가 저런 상황이고 이런 확률까지 안다고 했을때, 나는 과연 내 선택을 바꿀까? 확률이고 뭐고 처음의 선택을 믿고 싶어할 것 같다.

이건 간단히 시뮬레이션 할 수 있어서 한번 시뮬레이션 해 봤다.

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;
int main()
{
    srand( (unsigned)time( NULL ) );

    int numGames;
    cout << "# of games : ";
    cin >> numGames;

    int carRoom = -1;
    int firstChoice = -1;

    int numWinningWithoutSwitching = 0;
    for ( int i = 0; i < numGames; ++i )
    {   /*don't switch a choice*/
        carRoom = rand() % 3;
        firstChoice = rand() % 3;

        if ( carRoom == firstChoice )
            ++numWinningWithoutSwitching;
    }

    int numWinningWithSwitching = 0;
    for ( int i = 0; i < numGames; ++i )
    {   /*switch a choice*/
        carRoom = rand() % 3;
        firstChoice = rand() % 3;

        if ( carRoom != firstChoice )
            ++numWinningWithSwitching;
    }

    cout
        << "# of winning games without switching : "
        << numWinningWithoutSwitching << " ["
        << static_cast<float>(numWinningWithoutSwitching) / numGames
        << "%]" << endl;
    cout
        << "# of winning games with switching : " << numWinningWithSwitching
        << " [" << static_cast<float>(numWinningWithSwitching) / numGames
        << "%]" << endl;

    return 0;
}

# of games : 1000000
# of winning games without switching : 332977 [0.332977%]
# of winning games with switching : 666691 [0.666691%]