Hacker News new | past | comments | ask | show | jobs | submit login

  A small simulation in Python

  from random import randint
  oneBoy=0
  twoBoys=0

  # 0 = boy, 1 = girl
  for i in range(10000):
      s1 = randint(0,1)
      s2 = randint(0,1)
      if s1 * s2 == 0:  # Here is at least one boy
          oneBoy = oneBoy+1
          if s1 == s2:  # Here are two boys
              twoBoys = twoBoys+1
  print("Two Boys")
  print(float(twoBoys)/float(oneBoy))

  # As expected the result is near 1/3.

  oneBoyT=0
  twoBoysT=0
  #days 0=Monday, 1=Twesday ...
  # (0,1) means (sex,day) = a boy was born one Twesday

  for i in range(1000000):
      s1 = randint(0,1)
      d1 = randint(0,6)
      s2 = randint(0,1)
      d2 = randint (0,6)
      if (s1,d1)==(0,1) or (s2,d2)==(0,1):
          oneBoyT = oneBoyT+1
          if s1 == s2:
              twoBoysT = twoBoysT +1
  print("Two Boys in Twuesday")
  print(float(twoBoysT)/float(oneBoyT))

  # The simulation gives a result near 1/3, 
  # this is a hint to prove that 13/27 is incorrect
  # under the assumption that the population sex and
  # day are independent, and with probability 1/2 and 1/7

  # if you want to convince me otherwise, I'll be 
  # glad to see the code to generate the population
  # and the estimated probability.



Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: