Created
April 15, 2019 17:27
-
-
Save vfrico/d10f468eb175f8b5fb785d64c8efa2f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with:
or