Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/env python3
- import random
- def get_random_exclude(*n):
- while True:
- ran = random.randint(0,2)
- if ran not in n:
- return ran
- def montyhall(first_behaviour, second_behaviour):
- doors = [False, False, False]
- doors[random.randint(0,2)] = True
- car = doors.index(True)
- # First user decission
- user1 = first_behaviour()
- # Host shows a goat
- host1 = get_random_exclude(user1, car)
- # User decides again (he must know his first decission and the door where the goat is)
- user2 = second_behaviour(user1, host1)
- return doors[user2]
- def test(n, behaviour):
- results = {True: 0, False: 0}
- if behaviour is "change":
- behaviour = lambda x,y: ({x, y} ^ {0,1,2}).pop()
- elif behaviour is "keep":
- behaviour = lambda x, y: x
- for i in range(0, n):
- result = montyhall(lambda: random.randint(0,2), behaviour)
- results[result] += 1
- print(results)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement