Thread: help me solve the puzzle

  1. #16
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Plus the variable names are utterly poor.
    Which has nothing to do with the problem.

    I think this has been solved or were the answers that were given incorrect?

  2. #17
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    It is in fact the same. Since half the Breeders have boys and half have girls, the number of breeders goes down each breeding cycle, but not the ratio of boys to girls, since they will always be half boys and half girls (in a perfect world). Specifically the ratio will always approach the ratio of male.female births. In real life, more boys are conceived, but more girls are born. Male fetus's have a higher rate of miscarriage. You shoudl also take into account multiple births , both fraternal and identical.

    Here is the proof -

    Code:
    #include <stdio.h>
    
    
    int main(){
    
    	double Boys = 0.0;
    	double Girls = 0.0;
    	double Breeders = 1.0;
    
    	while(Breeders > 0.0){
    		Breeders /= 2.0;
    		Boys += Breeders;
    		Girls += Breeders;
    		printf("Boys - %f  Girls - %f \n" , Boys , Girls);
    		}
    
    	return 0;
    	}
    Last edited by abachler; 08-29-2009 at 01:28 PM.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Again, this cannot be proof because you cannot have a half child or half families left that needs to breed a boy.
    Eventually, the number cannot be evenly divided by 2, and this is where most algorithms of this kind fails. I have yet to see any good, realistic algorithm to present the answer of a 1:1 ratio.
    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.

  4. #19
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by Elysia View Post
    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.
    @cyberfish: Yeah, you were right. I did it right in my first post, but somehow I managed to screw it up in the second.
    Your answer was right. It's 50/50. If you don't believe me/us, then go ahead and read my proof and write a program yourself to find out what number it converges to. It will be one. So except for the converging thing the matter has been proved in my post (well, of course you have to fix it for the mistake I made that cyberfish pointed out, but those changes are trivial).
    So for everybody: yes, the answer has been given.

    Elysia.... Well, really... I don't care. I wrote this program not to be readable, but to as quickly as I could write the program without even thinking. I didn't write it for you guys, except maybe to run it to get the answer. Also, the variables are used little enough for the program still to be understood in one glance of the eye.
    No complains about using namespace std? About using parenthesis between a/b which is completely non-required (I have no idea why I put them there, I just typed it out without thinking, as I said). About the infinite loop where I obviously should have an ending when the solution is close enough?
    Well, let's say we're lucky I will never sell the program, or release it as open source software.

    "nor can there be 12.5 families left that needs to have a boy."
    Can you explain that sentence? You obviously didn't read, or completely understand my post, as there is no part about half families or half babies. It assumes an infinite number of families, then I derive an obvious summation, and wrote a simple program to get the number it converges to. That part is no proof, and unless a lot of people are still unconvinced I shall not give it either. I don't even have it yet, either, but I guess I'd be able to figure it out.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by EVOEx View Post
    Elysia.... Well, really... I don't care. I wrote this program not to be readable, but to as quickly as I could write the program without even thinking. I didn't write it for you guys, except maybe to run it to get the answer. Also, the variables are used little enough for the program still to be understood in one glance of the eye.
    No complains about using namespace std? About using parenthesis between a/b which is completely non-required (I have no idea why I put them there, I just typed it out without thinking, as I said). About the infinite loop where I obviously should have an ending when the solution is close enough?
    Well, let's say we're lucky I will never sell the program, or release it as open source software.
    The variable names suck. I couldn't make out what the heck they meant or what was what. I give you 0 out of 10 for that code.
    And yes, you should probably have broken the loop when the solution was found, otherwise it wouldn't be proof, but more of an informative program.

    "nor can there be 12.5 families left that needs to have a boy."
    Can you explain that sentence? You obviously didn't read, or completely understand my post, as there is no part about half families or half babies. It assumes an infinite number of families, then I derive an obvious summation, and wrote a simple program to get the number it converges to. That part is no proof, and unless a lot of people are still unconvinced I shall not give it either. I don't even have it yet, either, but I guess I'd be able to figure it out.
    You didn't start at 100 families as the question said, but the point is the same. Each time there is 50% chance to get a boy.
    So, first, 50 families get a boy.
    Then 25 families get a boy.
    Then 12.5 families get a boy (!). There can't be 12.5 families. It's not possible, put simply, and therefore it is wrong.
    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. #21
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by Elysia View Post
    The variable names suck. I couldn't make out what the heck they meant or what was what. I give you 0 out of 10 for that code.
    And yes, you should probably have broken the loop when the solution was found, otherwise it wouldn't be proof, but more of an informative program.


    You didn't start at 100 families as the question said, but the point is the same. Each time there is 50% chance to get a boy.
    So, first, 50 families get a boy.
    Then 25 families get a boy.
    Then 12.5 families get a boy (!). There can't be 12.5 families. It's not possible, put simply, and therefore it is wrong.
    Come on, are you trolling here or what?

    You give me a 0 ou tof 10 for that code. Well woohoo. It's no test. I don't care if you don't understand it. By the looks of it there's a lot in this topic that you don't understand. As the answer has been stated properly several times.
    As I even said in the post: it IS no proof. It was *exactly* an informative program. Even if it was written properly it is no proof that this converges to that value, an actual proof would consist of actual math. So yes, newsflash: it WAS an informative program.
    And what the heck they meant. Well, if you looked at the formula I proposed you see that it is exactly that formula implemented. If you can't understand those few lines of C code, even if the variable names are poor, then I'm really underwhelmed by your code interpreting skills.

    But... 100 families? Maybe you should read before you complain. Nowhere there was an initial number of 100 families.

    Yes, I made a mistake in that post. But you've seemed to make a dozen already, if you're not trolling, which I'm not used to from you. It seems to me you just didn't read the posts properly. But I propose you read them properly before you complain about a legit statement being invalid.
    Or criticizing code that was never even meant to be good or readable, just to show the number my result converges to. And even if I didn't write it, if you'd actually read my formula I posted above that, I'd think you'd find the program fairly easy to understand.

  7. #22
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Ok. Before it becomes a heated discussion just stop this one here only. Here's another one.
    Every man in a village of 100 married couples has cheated on his wife. Every wife in the village instantly knows when a man other than her husband has cheated, but does not know when her own husband has. The village has a law that does not allow for adultery. Any wife who can prove that her husband is unfaithful must kill him that very day. The women of the village would never disobey this law. One day, the queen of the village visits and announce that at least one husband has been unfaithful. What happens?
    I think that every husband will be killed after that. Tell me if it's correct?
    Last edited by BEN10; 08-29-2009 at 09:59 PM.
    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

  8. #23
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    The first question doesn't represent genetic mosaics.

    The second question only serves to say that every male in the village is either homosexual or bisexual.

    Go play "Professor Layton".

    [Edit]

    "Tell me if it's correct?"

    Do you interpret "proof of guilt" as "no proof of innocence"?

    [/Edit]

    Soma
    Last edited by phantomotap; 08-30-2009 at 01:26 AM.

  9. #24
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Every man in a village of 100 married couples has cheated on his wife. Every wife in the village instantly knows when a man other than her husband has cheated, but does not know when her own husband has. The village has a law that does not allow for adultery. Any wife who can prove that her husband is unfaithful must kill him that very day. The women of the village would never disobey this law. One day, the queen of the village visits and announce that at least one husband has been unfaithful. What happens?
    Assuming the other people involved in the cheating do not confess....

    Nothing, unless only one woman did not know a husband has been cheating ( in which case she kills her husband).

    Because if more than one husband has been cheating the wives can not prove who it was as they all would know a husband has cheated at some point.

    If only one cheated it will be obvious to the wife as she has not known a husband was cheating (when all the other wives already knew).

    EDIT: Misread the question.

    Still nothing because if the wives have not killed their husbands already (when the discrete event of the queen's announcement happens) they have themselves disobeyed the law (to kill their husbands the day of the cheating).

    Unless all 100 husbands cheated earlier that day...
    Last edited by novacain; 08-30-2009 at 03:45 AM.
    "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

  10. #25
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by Elysia View Post
    Again, this cannot be proof because you cannot have a half child or half families left that needs to breed a boy.
    Eventually, the number cannot be evenly divided by 2, and this is where most algorithms of this kind fails. I have yet to see any good, realistic algorithm to present the answer of a 1:1 ratio.
    This is a statistical estimation, not a factual example (there are no numbers quoted in the original post for population or normal boy/girl ratio) and as such fractions to determine the weight of each outcome is perfectly valid.

    Also pointing out you have assumed an exactly equal chance of a boy or girl, which is not a given in the question (nor is it exactly correct in reality).

    Quote Originally Posted by Elysia View Post
    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.
    If Mike Tyson and Bill Gates had a boxing match there are two outcomes, Mike wins or Bill wins. I do not think that equates to a 50% of Bill Gates getting his ear bitten off.
    Last edited by novacain; 08-30-2009 at 02:29 AM.
    "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

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by EVOEx View Post
    You give me a 0 ou tof 10 for that code. Well woohoo. It's no test. I don't care if you don't understand it. By the looks of it there's a lot in this topic that you don't understand. As the answer has been stated properly several times.
    As I even said in the post: it IS no proof. It was *exactly* an informative program. Even if it was written properly it is no proof that this converges to that value, an actual proof would consist of actual math. So yes, newsflash: it WAS an informative program.
    And what the heck they meant. Well, if you looked at the formula I proposed you see that it is exactly that formula implemented. If you can't understand those few lines of C code, even if the variable names are poor, then I'm really underwhelmed by your code interpreting skills.
    As I said, it was not informative because you failed to write good variable names, thus making it a mess instead of informative. Had you entered variable names, then yes, it would have been informative, albeit still flawed (you admitted it yourself that it has its limits).

    But... 100 families? Maybe you should read before you complain. Nowhere there was an initial number of 100 families.
    I did miss that one.

    Yes, I made a mistake in that post. But you've seemed to make a dozen already, if you're not trolling, which I'm not used to from you. It seems to me you just didn't read the posts properly. But I propose you read them properly before you complain about a legit statement being invalid.
    Or criticizing code that was never even meant to be good or readable, just to show the number my result converges to. And even if I didn't write it, if you'd actually read my formula I posted above that, I'd think you'd find the program fairly easy to understand.
    I have read the formulas, and they do make sense, but they cannot be applied to any real-world situation, unfortunately, and that is why I'm rejecting their use.

    Quote Originally Posted by novacain View Post
    If Mike Tyson and Bill Gates had a boxing match there are two outcomes, Mike wins or Bill wins. I do not think that equates to a 50% of Bill Gates getting his ear bitten off.
    Note that I never said that I believe in statistical mathematics, but there's just no way there is a 50/50 chance where you have two numbers, etc.
    Unfortunately, there's also no other way of calculating it.
    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.

  12. #27
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    These sound like questions from a Google Job Interview
    Spidey out!

  13. #28
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by Elysia View Post
    Note that I never said that I believe in statistical mathematics, but there's just no way there is a 50/50 chance where you have two numbers, etc.
    Unfortunately, there's also no other way of calculating it.
    There is if only one of those numbers is the outcome. If you can flip a coin and get both heads and tails, then that is what is strange, but it would fit what you seem to think probability is. Don't use your Harvey Dent coin next time you try an experiment like this.

  14. #29
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The coin can land on its edge, too. And it can heavily favor a specific side for a period of time too, so I wouldn't directly call these things "random." I don't believe one bit in the statistical mathematics.
    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.

  15. #30
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by Elysia View Post
    The coin can land on its edge, too. And it can heavily favor a specific side for a period of time too, so I wouldn't directly call these things "random." I don't believe one bit in the statistical mathematics.
    Probability does not promise interesting, that is, "random" results. What makes a probability true is if it accurately reflects the ratio of favorable outcomes to all outcomes. The actual outcome is a permutation of tries.

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