by jules · 7y ago · 0 comments
from random import random, randint
p_blue = 0.5
p_cheat = 0.1
def randbool(p): return random() < p
def randgenes(): return randbool(p_blue), randbool(p_blue)
def mate(mother, father): return mother[randint(0,1)], father[randint(0,1)]
def blueeyes(p): return p[0] and p[1]
n_cheat = 0
n_faithful = 0
for i in range(0,1000000):
mother = (True,False)
grandfather = randgenes()
grandmother = randgenes()
husband = mate(grandfather, grandmother)
lover = randgenes()
cheated = randbool(p_cheat)
if cheated:
kid1 = mate(mother, lover)
kid2 = mate(mother, lover)
else:
kid1 = mate(mother, husband)
kid2 = mate(mother, husband)
if blueeyes(grandmother) or blueeyes(grandfather) or blueeyes(husband) or not blueeyes(kid1) or not blueeyes(kid2): continue
if cheated: n_cheat += 1
else: n_faithful += 1
print(n_cheat)
print(n_faithful)
We get 4619 times cheated and 14226 times faithful. The probability of cheating went up substantially relative to the prior of 10%, but it's still below 30%. I'd say that the chaos wasn't justified.