The problem can be formulated as follows. As a participant of a game show, you have to choose one of three doors. Behind one of the doors is a prize, behind two other doors is nothing. After you pick a door, the game host, who knows where the prize is, selects a door with no prize from the two remaining doors, and opens it. Then the host tells you that you may stick to your original choice or switch to another closed door. Should you do it?
Player A would always stick to the original choice, while Player B would always switch the door.
from random import choice N = 100000 player_a_win = 0 # Palyer A sticks to the original choice. player_b_win = 0 # Palyer B switches the door. def monty_choice(prize, options): if prize[options[0]] == False and prize[options[1]] == False: return choice(options) return options[0] if prize[options[1]] == True else options[1] for _ in range(N): prize = [False, False, False] prize[choice([0, 1, 2])] = True options = [0, 1, 2] player_choice = choice(options) options.remove(player_choice) options.remove(monty_choice(prize, options)) if prize[player_choice]: player_a_win += 1 if prize[options[0]]: player_b_win += 1 print(f"Player A: {player_a_win / N}") print(f"Player B: {player_b_win / N}")
Player A: 0.33323 Player B: 0.66677
Player B, who always switches doors, wins twice more often!
If your intuition still rebels, here is an easy way to think about this game. Suppose you have initially chosen a door with the prize. The chances of this lucky event are 1 out of 3. In this case, switching doors means failure: you move away from your prize. However, in any other case (2 out of 3) you choose between your empty door and another closed door with the prize behind. Therefore, “always switch” strategy wins in 2/3 of all the games.
标签:door,prize,Player,Hall,choice,player,problem,options,Monty From: https://www.cnblogs.com/zhangzhihui/p/18346838