Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import random
  2.  
  3. doors = [1,2,3]
  4. nb_simulations = 1000000
  5. win_door1 = 0
  6. win_door2 = 0
  7.  
  8. for i in range(nb_simulations):
  9.     winning_door = random.choice(doors)
  10.     player_door1 = random.choice(doors)
  11.  
  12.     # Open a door
  13.     doors_openable = doors.copy()
  14.     doors_openable.remove(player_door1)
  15.     if player_door1 != winning_door:
  16.         doors_openable.remove(winning_door)
  17.     doors_opened = random.choice(doors_openable)
  18.  
  19.     # Change ?
  20.     doors_selectable = doors.copy()
  21.     doors_selectable.remove(doors_opened)
  22.     doors_selectable.remove(player_door1)
  23.     player_door2 = doors_selectable[0]
  24.  
  25.     if winning_door == player_door1:
  26.         win_door1 += 1
  27.     if winning_door == player_door2:
  28.         win_door2 += 1
  29.  
  30.  
  31. freq_win_door1 = win_door1 / nb_simulations
  32. freq_win_door2 = win_door2 / nb_simulations
  33.  
  34. if 0.33 < freq_win_door1 < 0.34 and 0.66 < freq_win_door2 < 0.67:
  35.     print(True)
  36. else:
  37.     print(False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement