This is one of those questions that gets under a programer’s skin:

Supposed a society where people prefer boys. They will keep having children until they get a boy and then stop. What will be the percentage of boys to girls in this society?

#### Programers Like to Complicate Things:

I immediately started drawing out trees with ever shrinking percentages. It looked like a convergent series: half the families will get boys on the the first try, a quarter will get them on a second try, and eighth on their third try, and so on and so on.

Some of us proposed that since families could have huge amount of girls before reaching boys, and the most boys any family would have would be one; then the girls would end up out numbering the boys. If you looked at it as a infinite series of ever halving chances, then it would converge to 1…which must mean something.

But the simplest answer was just to play the odds. Every child has a 50/50 chance of being a boy, just like coin flips. If you let all the girl families spin again; they would have a 50/50 chance of a boy and only be adding 50% to the population. So it would wash out to 50/50.

#### Brute Force

I decided to write a program to test it out: (https://github.com/lucasmcgregor/how_many_babies)

USAGE: simple_baby.py number_of_families max_family_size

simple_baby.py simulates a number of families trying to have a boy. Each attempt is 50/50 chance. Once a family hits the max number of children, they have run out chances.

I ran 10 trials of 1,000,000 families with a max size 100. So some (un)lucky family might end up with 100 girls!

- Percent Boys: 49.99%
- Standard Deviation between trials: 0.03%

To check my random seed, I ran a “control.py,” which just flipped a virtual coin to pick boys or girls. Families in the control group each got one child, which allowed me to see just how much deviation was in my randomizer. After 10 trials of 1,000,000 families:

- Percent Boys: 50.45%
- Standard Deviation between trials: 1.5%

So the simple_baby.py showed that families allowed to have up to 100 children, still ended up with 50% of the population as boys. Over then ten trials, I created a histogram of how many attempts it took for each family to get their boy.

First, no family took more than 24 tries.

Second, you can see the number of attempts required goes down logarithmically, which is exactly what a infinite series converging at 1 should do.

#### Family Planning

24 children in one family!?! This is not the real world. To be more realistic, let’s cap the families.

I ran from one child — which gives an obvious 50/50, up to five. I thought around five, you have all these families that needed to have more than five children to hit that boy before being capped. So each family who needed six or more attempts, now is just contributing 5 daughters and no sons. Would that shift the balance towards the ladies? Or does the decline in over all people (they are adding only 5 as opposed to the 24 in one cases) balance out?

Once again, programmers over complicate simple things. 50/50 odds are still 50/50 odds. With each cap, the number remained 50/50 within standard deviation.

#### Generation Gap?

But what about generations?

What if the shift was small, but it could be compounded over generations. If you thought of rats instead of people; you can make the breeding rules more simple. Each female would be allowed a maximum number of offspring (always stopping when she has her first boy). In the next generation, the limiting factor would be the number of females born, they have the children after all.

Thinking rats, I don’t have to worry about incest or running out of males. In theory, one male should be enough to get an entire colony of lady rats knocked up.

USAGE mom_multi_gen.py number_of_families max_family_size number_of_generations generation_life_span

This program starts the same as simple_baby.py, but it then breeds all the females of the next generation for as many generations as you ask. Then it totals the last X generations for your population — for instance, after 1,000 generations of breeding; the last three generations are still alive and all need to be counted.

I ran my normal 1,000,000 families, 5 children, 1,000 generations, with a life span of 3 generations.

For each generation, the population remained stubbornly 50/50 within the standard deviation.

What I didn’t expect was that it NEVER made it to 1,000 generations.

#### Female Troubles

In fact, none of my trials had a population after 600 generations, because 50% of the families had a boy, they contributed no girls to the next generation. So while the ratios of boys to girls remained the same; the total number declined.

So in a way, it is a trick question. What percentage will be boys? What is half of zero?