# The fact as ALREADY happened.
# BG/GB being DIFFERENT is NOT THE TWIST.
# Whether they are or not it will amount to 50% total.
# TWIST: BB is not possible.
def boy_girl_problem():
from random import choice
families = {}
for i in range(1000):
families[i] = []
families[i].append(choice(['BOY', 'GIRL']))
families[i].append(choice(['BOY', 'GIRL']))
had_both_sex = filter(lambda f: set(f) == set(['BOY', 'GIRL']), families.values())
had_two_boys = filter(lambda f: 'GIRL' not in f, families.values())
return len(had_both_sex) / float(len(families) - len(had_two_boys))
# average(boy_girl_problem) == 2/3