Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #!/bin/env python3
  2. import random
  3.  
  4. def get_random_exclude(*n):
  5. while True:
  6. ran = random.randint(0,2)
  7. if ran not in n:
  8. return ran
  9.  
  10. def montyhall(first_behaviour, second_behaviour):
  11. doors = [False, False, False]
  12. doors[random.randint(0,2)] = True
  13. car = doors.index(True)
  14.  
  15. # First user decission
  16. user1 = first_behaviour()
  17.  
  18. # Host shows a goat
  19. host1 = get_random_exclude(user1, car)
  20.  
  21. # User decides again (he must know his first decission and the door where the goat is)
  22. user2 = second_behaviour(user1, host1)
  23.  
  24. return doors[user2]
  25.  
  26. def test(n, behaviour):
  27. results = {True: 0, False: 0}
  28. if behaviour is "change":
  29. behaviour = lambda x,y: ({x, y} ^ {0,1,2}).pop()
  30. elif behaviour is "keep":
  31. behaviour = lambda x, y: x
  32.  
  33. for i in range(0, n):
  34. result = montyhall(lambda: random.randint(0,2), behaviour)
  35. results[result] += 1
  36.  
  37. print(results)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement