# The barbarian king [duplicate]

A barbarian king wants his tribe to have more men than women, because men can fight and women cannot. to achieve this, he introduces the following law:

Each couple has to produce babies until they have at least one boy. Then they must stop producing babies.

By doing this, he ensures that every couple has a boy, and some couples will have zero girls.

But his councillor sees a flaw in this plan. He says that to have more boys than girls he needs to make the opposite law.

Each couple has to reproduce as long as they get boys. When they get a single girl, they have to stop.

By doing this, some couples will get many boys, and none will ever get more than one girl.

Which law would get the most boys?

Note: The barbarian king does not care about the total number of babies. He just wants more boys than girls.

• Answers also provided on MathOverflow and Math.se
– Len
Feb 20 '15 at 2:44
• So, "Which law would get the most boys?" actually means "Which law would get the most boys compared to girls?", i.e. "Which law has the higher expected difference of number of boys minus number of girls?"?
– xnor
Feb 20 '15 at 3:21
• Maybe this question should be closed because it is a math puzzle, not a logic-puzzle. Look at the answers that are being generated. The non-math answers are voted down, while the un-puzzle-like answers are receiving votes. Feb 20 '15 at 6:13
• @BGM It's actually that your 'logic-only' answer is wrong in conclusion and incomplete in its logic. Feb 20 '15 at 9:30
• This puzzle always seems to appear in a form which would result in a gradually diminishing population. For a stable population each couple should have 2 children - i.e. 2 births to match their 2 deaths (for a very simple model). Feb 20 '15 at 9:37

The best answer IMHO was given as a comment to this question:

For each birth, the probability of a boy is 50% and the probability of a girl is 50% (for the purposes of this exercise; the real world is more complicated). Therefore, the ratio for all births must be 50:50. The number of previous births in each family, and the genders of those children, is irrelevant.

author: Mike Scott Feb 4 '11 at 17:28

If you are not convinced yet, think of this in the following way. Each year $i$, there is a set $C_i$ of couples that are allowed to have a baby and do so. The initial subset $C_1$ is the set of all couples, and it becomes smaller and smaller when more and more couples are banned from reproducing. So each year, the number of new babies is $|C_i|$. But, assuming the ratio is 50:50, each year there will be on average $|C_i|/2$ boys and $|C_i|/2$ girls! This does not depend at all on the number and identity of couples in $C_i$.

• +1 I love this answer! This is a lovely puzzle because it encourages you to refer to probability calculation, and you can get a correct answer just by applying logic.
– Kos
Feb 20 '15 at 12:08
• It becomes even clearer if you imagine that the barbarian king actually asks the couples to "flip a coin", and he wants "more heads than tails". Feb 20 '15 at 13:19
• @DanielDaranas That comment seems worthy of its own answer. It's a very intuitive way to explain it. Feb 20 '15 at 18:27
• While the observation that each individual birth has a 50:50 chance of being a boy or a girl is correct, I'm afraid it's not sufficient to prove the equality of the two laws. You also need to take the specifities of the laws into account. This becomes clear when you consider a third law: All couples have to keep on producing babies until they have exactly one son more than daughters. Obviously, your argument holds for this law just as much as for the two original ones, but it does not imply that the tribe will end up with the same expected number of boys and girls. Feb 22 '15 at 11:01
• According to your law, indeed there will be some couples that will continue having children forever. Feb 23 '15 at 15:30

Under the assumption that

• The probability of getting a girl or a boy is equal (50%)
• A male can only put his thang on his partner female (no multiple wives)

Neither of them will get significantly more boys than the other (in a long period of time)

# A Priori Proof :

## Barbarian King

In regex: (G*)B

            ...
G
G       B
Z       B
B


The tree goes from left to right.

Z = initial state; G = girl; B = boy;

The probability of getting 1 boy and 0 girls is 1/2.
The probability of getting 1 boy and 1 girl is 1/4.
The probability of getting 1 boy and 2 girls is 1/8.
The probability of getting 1 boy and N girls is 1/2^(N+1).


### To solve the average difference of boys and girls under the Barbarian King's rule, we would need the following :

$$\lim_{N\to \infty} \frac{\sum_0^N((\mbox{BoyCount}-\mbox{GirlCount})*\mbox{probability}))}{N}$$

$$\lim_{N\to \infty} \frac{\sum_0^N(\frac{1-N}{2^{N+1}}))}{N} = 0$$

Check this wolfram solution to this equation. (Sorry Barbarian King)

This means that in the long run (approaching $\infty$), there is no ($0$) significant difference between the number of boys and girls under the Barbarian King's rule.

## Councillor

In regex: (B*)G

    G
Z       G
B       G
B
...


The tree goes from left to right.

Z = initial state; G = girl; B = boy;

The probability of getting 0 boys and 1 girl is 1/2.
The probability of getting 1 boy and 1 girl is 1/4.
The probability of getting 2 boys and 1 girl is 1/8.
The probability of getting N boys and 1 girl is 1/2^(N+1).


### To solve the average difference of boys and girls under the Councillor's rule, we would need the following :

$$\lim_{N\to \infty} \frac{\sum_0^N((\mbox{BoyCount}-\mbox{GirlCount})*\mbox{probability}))}{N}$$

$$\lim_{N\to \infty} \frac{\sum_0^N(\frac{N-1}{2^{N+1}}))}{N} = 0$$

Check this wolfram solution to this equation. (Sorry Councillor)

This means that in the long run (approaching $\infty$), there is no ($0$) significant difference between the number of boys and girls under the Councillor's rule.

# A Posteriori Proof :

Open your JavaScript console (F12->Console or Ctrl+Shift+J) and copy and paste the below code.

function makeBabies(couples,simulations){
var kingBabies={boys:0,girls:0};
var councillorBabies={boys:0,girls:0};

for(var j=0;j<simulations;j++){
for(var i=0;i<couples;i++){
//Barbarian King
while(Math.random()<0.5){
kingBabies.girls++;
}
kingBabies.boys++;

//Councillor
while(Math.random()<0.5){
councillorBabies.boys++;
}
councillorBabies.girls++;
}

//reset simulation
kingBabies={boys:0,girls:0};
councillorBabies={boys:0,girls:0};
}

//average

}


Type makeBabies(<couples>,<simulations>) and replace <couples> with the number of couples that you want in your simulation, and <simulations> with the number of times you want to run the same test.

## Results :

makeBabies(100,10000) = 0.0488, -0.0228
makeBabies(1000,10000) = 0.3019, -0.1117
makeBabies(10000,10000) = -2.47, -0.4471


10000 simulations each time, with increasing number of couples (100, 1000, 10000).

As you can see, the average advantage of boys over girls in both methods is very insignificant. (Most of the time < 1)

You can try out the code and run more simulations if you want.

• This is clearly the correct/desired answer, but if different men have different percentages of X/Y sperm, then the second policy would have an advantage. Feb 20 '15 at 2:36
• It is a scientifically proven fact that some couples are more likely to produce male offspring than female offspring (and vice-versa), so the 50/50 assumption is wrong. Feb 20 '15 at 4:09
• @MichaelRize, you can say that the assumption is not accurate to real life but you can't say it's wrong since, you know, I assumed it. Feb 20 '15 at 4:14
• You know what I mean ;-) .. I mean it is not an accurate model that mirrors the genetical likelihood that a boy or girl will be born. The second model rewards genetics, the first does not. So the second model wins. Feb 20 '15 at 4:17

Under the first formula, all parents will have exactly one boy while under the second formula, all parents will have exactly one girl. But how many children of the opposite gender can they expect in both cases?

Let $X$ be a random variable that counts the number of children of opposite gender, i.e., the number of girls under formula 1 or the number of boys under formula 2. The expected value of a discrete univariate random variable is defined as the sum over all possible values multiplied by their probability:

$$E[X] = x_1 \cdot p_1 + x_2 \cdot p_2 + \dots$$

In our case, the possible values are the number of children, i.e., $x_1 = 0, x_2 = 1, x_3 = 2, \dots$

Every possible sequence of children will look something like this:

$$A\ A\ A\ A\ A\ B$$

that is, all children in the sequence have the same gender except the last one. For every child that is born, the probability that it is a girl or a boy is $50:50$ (presumably), so if the sequence consists of $n$ children, its probability is $\frac12\cdot\frac12\cdot\dots\cdot\frac12$ ($n$ times). For instance, the sequence above would have the probability $\frac12\cdot\frac12\cdot\frac12\cdot\frac12\cdot\frac12\cdot\frac12 = \left(\frac12\right)^6$.

For the expected value we want to compute, this means:

$$P(X=0) = \frac12,\quad P(X=1) = \frac14,\quad P(X=2) = \frac18,\quad\dots$$

and thus

$$E[X] = 0 \cdot \frac12 + 1 \cdot \frac14 + 2 \cdot \frac18 + \cdots$$

Mathematically speaking, this is an infinite series. If we sum up all of its elements, we see that the sum converges to $1$:

$$\sum_{n=1}^\infty\frac{n-1}{2n}=1$$

That means that we expect the number of children of the opposite gender to be $1$. To sum up:

• Under formula 1, the number of boys for each couple is $1$ and the expected number of girls is $1$
• Under formula 2, the number of girls for each couple is $1$ and the expected number of boys is $1$

Thus we conclude that both formulas will lead to the same expected number of boys and girls for the barbarians.

• Much easier to understand your maths than other peoples'! Feb 20 '15 at 12:38
• Of course, your ultimate conclusion is wrong. You can't sum to infinity for number of live births per mother. Therefore the king's law would produce slightly more boys than girls. Feb 20 '15 at 12:48
• @AndyT Thank you - I was thinking of including a similar comment about infinity. But I guess it's sort of implicitly assumed in the question: you can't really answer the question "Which law would get the most boys?" in absolute terms because they allow for all kinds of outcomes. So the only thing that makes sense (I think) is to talk about expected values. That's how I tried to qualify my final conclusion. Feb 20 '15 at 13:20
• Plus my comment was wrong about the ultimate conclusion anyway... as I discovered when I wrote it up fully for my own answer! Feb 20 '15 at 13:27

Both will have the same outcome

Proof using a python simulation, assuming a population of 10,000 Couples:

For the 1st law:

from random import random

trials = 10000
numBoys=0
numGirls=0
for i in range(trials):
while(True):
Chance=random()
if Chance<0.5:
numBoys+=1
break
else:
numGirls+=1
print(numBoys)
print(numGirls)


For the 2nd law:

from random import random

trials = 10000
numBoys=0
numGirls=0
for i in range(trials):
while(True):
Chance=random()
if Chance<0.5:
numBoys+=1
else:
numGirls+=1
break
print(numBoys)
print(numGirls)


The results for Law 1 are as follows:

Trial 1: (10,000 Boys, 10028 Girls) Trial 2: (10,000 Boys, 9917 Girls) etc...

The results for Law 2 are as follows:

Trial 1: (9,884 Boys, 10000 Girls) Trial 2: (10,327 Boys, 10000 Girls) etc...

If you are somewhat knowledgeable about programming, you will realize the only difference in the code snippets is when I call "break". Basically, I am calling "break" whenever reproduction should be stopped. So you can see that in 1 law, reproduction is stopped whenever a boy is born, whereas in the other, reproduction is stopped whenever a girl is born.

Therefore:

You can expect the same outcome for each law.

Both laws produce:

the same number of boys and girls.

If the 1st Law is followed:

then a couple will add more boys than girls to the population, if it has 1 boy ( with probability 1/2) - and the net effect is +1 boy. It will add more girls than boys to the population if it has a sequence of children $GG^nB$ ( $n \geq 1$) with probability $1/2^{n+2}$ and the net effect $-n$.

So the total net effect is:

$1/2 - \sum\limits_{n=1}^\infty {n/2^{n+2}} = 0$

The same reasoning applies to Law 2 in reverse.

Assumption: Each birth has a 50:50 chance of being boy:girl. Statement: A woman cannot have an infinite number of children.

Let's consider both laws at once, by saying that you stop if you have an "A" child, but continue if you have a "B" child.

If a woman can have a maximum of two children in her lifetime, then we have a:

• 50% chance of 1st child being A
• 25% chance of 1st child being B and 2nd child being A
• 25% chance of 1st child being B and 2nd child being B
• This sums to an average per woman of 0.75 As and 0.75 Bs

If a woman can have a maximum of three children, then we have a:

• 50% chance of 1st child being A
• 25% chance of 1st child being B and 2nd child being A
• 12.5% chance of 1st child being B, 2nd child being B, and 3rd child being A
• 12.5% chance of 1st child being B, 2nd child being B, and 3rd child being B

This sums to an average per woman of 0.875 As and 0.875 Bs

You can extend the maximum number of children per woman as much as you want (to whatever you think the biological limit is), but you'll end up with the same average number of As and Bs.

Short answer: The second rule is a lot more promising I say.

Long answer: No fancy mathematics from me here, but pure logical reasoning.

First a few general thoughts about the rules themselves.

If you apply one of those rules you actually set the maximum possible number of children having the specified gender, while the number of children having the opposite gender remains uncontrolled (open to be anything from zero to pretty much infinity in theory)

Assuming we have a realistic setting, you do have a finite number of possible couples. Thus you already know the exact number of children of the specified gender that you will get eventually.

Now you could start and assume a 50/50 ratio for the general populace as most people here do. If you do so you would probably end up having one of the many mathematical calculated results, giving you a pretty much equal chance of success or failure for both rules. In other word: by mathematical reasoning it would pretty much be a gamble each way.

BUT

Since nature is a little bit more complicated I find it better to say you have a 50/50 ratio for the populace in general and thus have individual ratios for every woman around (or every couple around since the father does affect the outcome too). Considering this it would most definitely be much more promising to go with the second rule (stopping family growth once a girl is born) suggested, as it rules out every couple with a high chance of giving birth to girls while not restraining couples that - on a biological level - favor boys.

Don't get me wrong here: it still is a gamble, since no one can guarantee there are couples giving birth to multiple sons (or any sons at all for that matter). But at least you prevented the possibility of having a finite number of boys vs a theoretically infinite number of girls.

After running the simulation and researching the internet:

CONCLUSION

Some couples are more genetically prepossessed to produce male offspring, so purely because of this fact, the 2nd method will produce more male babies. This problem cannot be solved purely with math, or you would think both methods produce identical results. The first method does not guarantee more boy babies than girl babies, because that ratio is still 50/50.The second method allows more males per mother, but it is still a 50/50 ratio of boys and girls. However, because of x and y chromosomes and genetics, more boys will be produced in the 2nd method, since some couples are more likely to produce boys.

• I like the way you think but I would suggest that we can still use math even if you want to change the assumptions. Feb 20 '15 at 3:46
• In the real world, there are also some couples who are more likely to produce female offspring. It isn't just one way variance in favour of male offspring. Feb 20 '15 at 13:25
• If you want to bring genetics into it: in the long run, all methods bring about a 50:50 split. This is because when there is an imbalance, the rare sex will have a more offspring. There is evolutionary pressure forcing equal expenditure for male and female offspring. Feb 20 '15 at 15:55

Since some couples are more likely to produce offspring of the same gender (could be boy or girl) every couple should be required to have babies until they have had 2 girls. Families that are predisposed to have male offspring will produce much more babies, All of the "random" families will have about 1.5 girls and 1.5 boys. This is not one of the proposed laws, but theoretically could work.

If the time is very limited,

The first method guarantees that each couple will produce at least one boy but no more than one per family.

But if the time is not limited,

The second method produces the most boys, however it will take longer because many of the families will be eliminated from the pool as soon as they have a girl and will not have a chance to produce a boy at all. However, chance allowing, there is the possibility that many families will have multiple boys and so, over time they will accumulate.

Conclusion:

Method two has the possibility to produce the MOST boys, but method one has the possibility to produce more faster in a shorter period of time. Neither method is guaranteed to produce any boys at all.

• Your probability calculation is wrong... but at least you spotted what noone else seems to have: time is limited, i.e. each couple can't have an infinite amount of babies! Feb 20 '15 at 12:49
• I beg to differ. In method one, if there are 100 families, you can produce no more than 100 boys, period. In method number two, families can produce multiple boys and so exercise the chance to produce many boys in a row, and so can produce MORE than 100 boys. Neither is guaranteed to produce any at all. Feb 23 '15 at 2:35