Skip to content

Instantly share code, notes, and snippets.

@crizCraig
Last active August 20, 2020 23:38
Show Gist options
  • Save crizCraig/e8f0066d6301795b3d960c978cef196e to your computer and use it in GitHub Desktop.
Save crizCraig/e8f0066d6301795b3d960c978cef196e to your computer and use it in GitHub Desktop.
# In a family with two children, what are the chances, if **one** of the children is a girl, that both children are girls?
from random import random
n = 0
c = 0
for i in range(100000):
a = random() < 0.5
b = random() < 0.5
if a or b: # **one** implies _either_ child
n += 1
if a and b:
c += 1
print(c/n) # 1/3
# In a family with two children, what are the chances, if **the youngest** is a girl, that both children are girls?
n = 0
c = 0
for i in range(100000):
a = random() < 0.5
b = random() < 0.5
if a: # Only **the youngest** is a girl
n += 1
if b:
c += 1
print(c/n) # 1/2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment