How did I solve the Monty Hall problem.

Monty-Hall_problem

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. The problem was originally posed (and solved) in a letter by Steve Selvin to the American Statistician in 1975 (Selvin 1975a), (Selvin 1975b). It became famous as a question from a reader's letter quoted in Marilyn vos Savant's "Ask Marilyn" column in Parade magazine in 1990 (vos Savant 1990a):

Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?
The problem is a paradox of the veridical type, because the correct choice (that one should switch doors) is so counterintuitive it can seem absurd, but is nevertheless demonstrably true. The Monty Hall problem is mathematically closely related to the earlier Three Prisoners problem and to the much older Bertrand's box paradox. ...MORE...

The way I see it, if the first time you chose right (of course you don't know that, I'm speaking from a "higher power" aspect...), then at the second time, if you change, you will lose the car. And if the first time you chose wrong, at the second time if you change your decision, you will win. So in all, the probability of you chose right in the first time is 1/3, and 2/3 for you to chose wrong.

Thus, the probability of you chose wrong the first time (2/3) equals the probability of you change your decision in the second time then win the cat (2/3).

So, we concluded that if you change your decision in the second time, chance for you to win the car is 2/3. Which means you should change your decision...

Computer simulation

For some people, this solution is hard to process at the beginning, I know I am. So, why not ask the computer to simulate this puzzle, and tell us directly which way I can get the car more likely.


        import random

        '''
        Yang (Simon) Guo
        https://sgyzetrov.github.io
        Monty_Hall_Simulation @ 2018-06-02
        '''
        
        def choose(iteration = 1000, change = 'n'):
            win_car = 0
            win_goat = 0
            prize_layout = random.randint(1, 3)
            if prize_layout == 1:
                door = ['goat', 'goat', 'car']
            elif prize_layout == 2:
                door = ['car', 'goat', 'goat']
            elif prize_layout == 3:
                door = ['goat', 'car', 'goat']
            for i in range(1, iteration + 1):
                init_choice = random.randint(0, 2)
                if change == 'n':
                    if door[init_choice] == 'goat':
                        win_goat = win_goat + 1
                    else:
                        win_car = win_car + 1
                elif change == 'y':
                    if door[init_choice] == 'goat':
                        win_car = win_car + 1
                    else:
                        win_goat = win_goat + 1
            print("win_car: %d (%.2f%%)" % (win_car, win_car * 100 / iteration))
            print("win_goat: %d (%.2f%%)" % (win_goat, win_goat * 100 / iteration))
        
        if __name__ == '__main__':
            print("-------- NOT change scenario --------")
            choose(10000, 'n')
            print("-------- change scenario --------")
            choose(10000, 'y')
        

And the output is presented below:


        -------- NOT change scenario --------
        win_car: 3369 (33.69%)
        win_goat: 6631 (66.31%)
        -------- change scenario --------
        win_car: 6683 (66.83%)
        win_goat: 3317 (33.17%)
        

Looks like we have a winner...