help me solve the puzzle

This is a discussion on help me solve the puzzle within the General Discussions forums, part of the Community Boards category; Here is the puzzle: In a village in each family they give birth to children till they get a boy, ...

  1. #1
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804

    help me solve the puzzle

    Here is the puzzle:
    In a village in each family they give birth to children till they get a boy, if girl child they try again. What is the ratio of boys to girls?

    I've thought of it over 100 times but still not getting in the right way. So please help.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    My guess would be that this has no effect on the ratio of boys to girls.

    Each birth has the same probability of a girl versus boy (which may not be 1:1).

    This just changes the number of children each family has, not the ratio.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    It does have effect...
    1/2 of the families have 1 boy
    1/4 of the families have 1 boy 1 girl
    1/8 of the families have 1 boy 2 girls...

    Don't have time to think it out now, but try like that...

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Damm you OP! This one has stuck in my head.

    if
    B == prob of a boy
    C == number of children in a family
    F == number of families in the village

    Number of boys will always be equal to the number of families (F).

    the number of girls in a family is [C-1]
    the number of families in the village with this number of children is [(1-B)^C * F]

    this gives the number of girls as the (1 to infinite) sum of

    (1-B)^C * F * (C-1)

    If we assume B == 1/2 we get

    G == ((C-1) * F ) / 2^C

    This is a rapidly diminishing sequence.

    My calcs show it tends to 'F' but I can not prove it.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    This is an interesting question, and I don't know if it has a real answer, since it depends on statistical luck.
    I'm poised to say it's 1:1, but that might be off.
    We can say for sure that there are 100 boys that are born in the end. The interesting this is that there will be about 100 girls, +/- 2/3 or so, as indicated by this algorithm:
    Code:
    #include <iostream>
    
    int main()
    {
    	int Boys = 0, Girls = 0;
    	int BoysTemp = 0;
    	int FamiliesLeft = 100;
    	while (FamiliesLeft != 0)
    	{
    		BoysTemp = FamiliesLeft / 2;
    		if (BoysTemp == 0)
    			BoysTemp = 1;
    		Boys += BoysTemp;
    		Girls += FamiliesLeft - BoysTemp;
    		FamiliesLeft -= BoysTemp;
    	}
    	std::cout << "Number of boys: " << Boys << "\nNumber of girls: " << Girls << std::endl;
    }
    Remember that the problem comes when the families that are left is an odd number. Then there cannot be born a similar number of boys and girls. From there, we can transcend into different paths and get different answers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    @Elysia
    Can you explain the algorithm. Why are you dividing by 2?
    @novacain
    Even I was also hitting my head on the wall to get the answer. I have few more puzzles like that, which I'm trying hard to get to the answer.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    Quote Originally Posted by BEN10 View Post
    @Elysia
    Can you explain the algorithm. Why are you dividing by 2?
    50/50. Half get boys. Half get girls.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Elysia View Post
    50/50. Half get boys. Half get girls.
    Why half? Why not all of them get a boy first? Or any other situation like that.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  9. #9
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    I believe it will be 50/50. It doesn't matter what they do, as long as they don't start killing people, every newborn has 50% chance of being a boy or a girl. Every birth is an independent event.
    Last edited by cyberfish; 08-29-2009 at 09:46 AM.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    Quote Originally Posted by BEN10 View Post
    Why half? Why not all of them get a boy first? Or any other situation like that.
    Why not defy mathematics?
    Because it clearly says that if there are two things that can happen, there is a 1/2 to get one of those things. Since there are two genders: boys and girls, there is a 50% chance to get either of them.
    This may or may not be realistic, but we don't have any better mathematical ways to calculate chance.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Let's say n people, everybody has at least a boy (I'll assume they are all in a "finished" state as there is no answer otherwise).
    That means there are n boys.

    1/2 of the families had 1 girl first.
    1/4 of the families had 2 girls first.
    1/8 of the families had 3 girls first.
    1/16 of the families had 4 girls first.
    etc.

    So the number of girls:
    1*(n/2) + 2*(n/4) + 3*(n/8) + 4*(n/16) + ...
    = n*(1/2 + 2/4 + 3/8 + 4/16 + ...)

    So the ratio is n:n*(1/2 + 2/4 + 3/8 + 4/16 + ...)
    or:
    11/2 + 2/4 + 3/8 + 4/16 + ...)

    A program I quickly wrote shows (doesn't proof; I still don't have time to look into it well enough) that that term converges to 2 when the number of families goes to infinity.
    So the answer is 1:2.

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
      double a, b, s;
    
      a = 1;
      b = 2;
      s = 0;
      while(1) {
        s += (a/b);
        a += 1.0;
        b *= 2.0;
        cout << s << endl;
      }
    }

  12. #12
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    1/2 - boy
    1/4 - girl + boy
    1/8 - girl + girl + boy
    1/16 - girl + girl + girl + boy
    ...

    Number of boys will obviously be 1 in each family, so we can try to prove that the average will also be 1 girl.
    Code:
    # girls = SUM_i=1_to_inf { 1/2^i * (i-1) } 
    => SUM_i=1_to_inf { i/2^i } - SUM_i=1_to_inf { 1/2^i }
    The second term is 1, so we need to prove that the first term converges to 2.

    (lol, the system won't let me post that without using code tags)

  13. #13
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    Quote Originally Posted by EVOEx View Post
    1/2 of the families had 1 girl first.
    1/4 of the families had 2 girls first.
    1/8 of the families had 3 girls first.
    1/16 of the families had 4 girls first.
    should be
    1/2 of the families had 0 girl first.
    1/4 of the families had 1 girls first.
    1/8 of the families had 2 girls first.
    1/16 of the families had 3 girls first.

    So there is 1 less girl in each family, and the ratio is 1:1.

    The answer to this question is easy, but hard to prove (if you don't accept the common sense proof).

  14. #14
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,475
    Quote Originally Posted by cyberfish View Post
    I believe it will be 50/50. It doesn't matter what they do, as long as they don't start killing people, every newborn has 50% chance of being a boy or a girl. Every birth is an independent event.
    In other words, they didn't change the actual event. So ratios stay the same. A family that has a lot of girls before they have their first boy will be offset by those events in which a boy was the firstborn on a 50/50 ratio.

    Curiously, by killing people one isn't changing the ratio. Newborns, even stillborns, should still be accounted for. That's the event. Or better... the moment of conception is the event.

    Similarly, by forcing a boy to be born one isn't changing anything. It's the actual event that needs to be tampered with if one wants to change the ratio used to measure it.

    EDIT: and you just proved it mathematically.
    Last edited by Mario F.; 08-29-2009 at 10:25 AM.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    Quote Originally Posted by EVOEx View Post
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
      double a, b, s;
    
      a = 1;
      b = 2;
      s = 0;
      while(1) {
        s += (a/b);
        a += 1.0;
        b *= 2.0;
        cout << s << endl;
      }
    }
    This is technically unfeasable.
    One family cannot have half a child, nor can there be 12.5 families left that needs to have a boy.
    Plus the variable names are utterly poor.

    cyberfish: It's usually because you use { and }. Post the reply with code tags around them or the entire post, then edit and remove them. It will work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 8 Puzzle game solver with the Best-First algoritm
    By LordMX in forum C Programming
    Replies: 17
    Last Post: 08-11-2008, 10:00 AM
  2. Replies: 12
    Last Post: 06-06-2008, 05:26 PM
  3. Crossword Puzzle Program
    By Loctan in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2006, 11:08 PM
  4. Solution to Google Puzzle 3,3,8,8=24
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-01-2006, 09:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21