Premium problem39. Does a Random Girl Have a Sister?

Hard Locked

family_probs maps a number of children to the proportion of families with that many, for example {1: 0.3, 2: 0.5, 3: 0.2}. Each child is a girl independently with probability p_girl. Pick a girl uniformly at random from all the girls in the population, and return the probability she has at least one sister.

The trap is sampling: you are choosing a girl, not a family, so a family with more girls is proportionally more likely to be the one you landed in.

  • a family of k children contributes girls in proportion to family_probs[k] * k
  • given the girl you picked, the other k - 1 children are still independent
  • so she has no sister with probability (1−pgirl)k−1(1 - p_{girl})^{k-1}

Input

family_probs = {1: 0.3, 2: 0.5, 3: 0.2}
p_girl = 0.5

Output

0.5

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)