Open In App

Puzzle | The Apocalypse

Puzzle:
In the new post-apocalyptic world, the world queen is desperately concerned about the birth rate. Therefore, she decrees that all families should ensure that they have one girl or else they face massive fines. If all families abide by this policy-that is, they have continued to have children until they have one girl, at which point they immediately stop-what will the gender ratio of the new generation be? (Assume that the odds of someone having a boy or a girl on any given pregnancy is equal.) Solve this out logically and then write a computer simulation of it.

Hints:



  1. Observe that each family will have exactly one girl.
  2. Think about writing each family as a sequence of Bs and Gs.

Solution:

Mathematically:



Below is the table illustrating the expected value of number of boys:

Sequence No of boys Probability No of boys * Probability
G        0     1/2                  0
BG        1     1/4                1/4
BBG        2     1/8                2/8
BBBG        3     1/16               3/16
BBBBG        4     1/32               4/32
BBBBBG        5     1/64               5/64
BBBBBBG        6     1/128              6/128

Logically:

Below is the pseudo-code calculating the probability of having a girl in the family-

double r unNFamilies (int n) 
{
    int boys = 0;
    int girls = 0;
    for (int i = 0; i < n; i++) 
    {
        int [] genders = runOneFamilY();
        girls += genders[0];
        boys += genders[1];
    }
    return girls / (double) (boys + girls);
}

int[] runOneFamily() 
{
    Random random = new Random();
    int boys = 0;
    int girls = 0;
    while (girls == 6) 
    {    
        // until we have a girl
        if (random.nextBoolean ()) 
        {    
            // girl
            girls += 1;
        } 
        else
        {  
            // boy
            boys += 1;
        }
    }
    int[] genders = {girls, boys};
    return genders;
}

If this pseudo-code is executed on large values if n, then the result will be very close to 0.5.

Article Tags :