News for hackers. Stuff that matters.
Re:The question is wrong by paul on Saturday January 03, 2009 @06:57PM (#418786)
Nope. Announcing the gender of one child does not magically alter the gender of the other child. It's like a print statement in code. If you don't believe me, try writing some code to simulate this. I will bet you an arbitrary amount of money that I'm right :)

Here's another way of looking at it: By your logic, if I announce that one of the children is a girl, then the other child only has a 1/3 chance of also being a girl. Likewise, if I announce that one of the children is a boy, then the other child only has a 1/3 chance of being a boy. Therefore, by your logic, the act of my arbitrarily announcing the gender of one of the children increases the probability that the other child is of the opposite gender from 1/2 (what it was before I spoke) to 2/3, regardless of whether I said it was a girl or boy. Hopefully you can see why this is not correct.

Re:The question is wrong by randallsquared on Saturday January 03, 2009 @07:12PM (#418793)
"Announcing the gender of one child does not magically alter the gender of the other child."

Nor is that what I said. :)

Assuming you meant "chance of being a boy" where you said "chance of being a girl", I agree that announcing the gender of one of the two children increases the probability of the other child being the opposite gender from 1/2 to 2/3.

The reason this is so is that some of the original probability was sunk in a case you've now eliminated: the case where there were two of the gender you didn't announce.

[Edit: Jeff already wrote some code, and while I haven't bothered to review it, I assume the lack of outcry about it indicates its correctness. Care to share where he got that wrong?]

Re:The question is wrong by paul on Saturday January 03, 2009 @07:25PM (#418803)
So if I ask all of my friends who have two children to "tell me the gender of one of their children", then you think that after they answer the question, there is a 2/3 chance they have both a boy and a girl? (but before answering the question the probability was 1/2) Doesn't that seem a little absurd to you?

If Jeff wrote code that yielded 2/3, then he was implementing my "algorithm 1" (which has selection), not the second algorithm (which does not do any selection).

I just updated my post with an explanation that may clear things up for you.

Re:The question is wrong by nostrademons on Sunday January 04, 2009 @12:05AM (#419014)
I thought it might be instructive to implement both algorithms side-by-side in the same loop:

    import random

    jeff_stats = { 'boy_and_girl': 0, 'two_girls': 0 }
    paul_stats = { 'boy_and_girl': 0, 'other': 0 }

    for i in xrange(100000):
        children = [random.randint(0, 1), random.randint(0, 1)]

        # Jeff's algorithm
        if children[0] or children[1]:
            print 'I have a girl'
            if children[0] and children[1]:
                jeff_stats['two_girls'] += 1
            else:
                jeff_stats['boy_and_girl'] += 1
        else:
            print "Oops, I'm a liar - I have no girls, so don't count me"

        # Paul's algorithm
        print 'I have a ' + ('girl' if children[0] else 'boy')
        if children[0] != children[1]:
            paul_stats['boy_and_girl'] += 1
        else:
            paul_stats['other'] += 1

    print "Jeff stats: " + str(jeff_stats)
    print "Paul stats: " + str(paul_stats)
Output (ignoring the actual printouts for each person):

    Jeff stats: {'boy_and_girl': 50027, 'two_girls': 24949}
    Paul stats: {'boy_and_girl': 50027, 'other': 49973}
I liked tromino's explanation best: it's really an ambiguity in the English language. Under your 2nd algorithm, 1/4 of parents can't truthfully announce "I have a girl" - but in ordinary conversation, this doesn't matter, because they'd just truthfully say "I have a boy" and we don't make a distinction. It's only when we explicitly filter out parents who don't have a boy that we change the probabilities.
Re:The question is wrong by randallsquared on Saturday January 03, 2009 @07:39PM (#418812)
The question "what is the gender of one of your children" gives you some information about the gender of both of their children. It's enough information to eliminate the case where both children are the gender opposite the one they mentioned.

It can still be the case that the chances of there being a boy and a girl are 1/2, while the chances of there being a boy after you find out about a girl are 1/3, purely because you don't know whether you found out about an older or younger girl. Probability is just a function of our ignorance (at least in this case; I'm not qualified to have an opinion about whether it always is).

[Edit: Hm. Looking again, it seems Jeff Atwood's code is for a different problem he was also discussing, so nevermind. After considering your update, I think you might be right.]

[Further edit follows:]

Here's some python that essentially shows you're correct, unless I flubbed it:

    firstpickwasboy = {'boy':0, 'girl':0}
    firstpickwasgirl = {'boy':0, 'girl':0}
    
    choices = ['boy', 'girl']
    
    for i in range(100000):
      children = [random.choice(choices), random.choice(choices)]
      whichchild = random.randint(0, 1)
      otherchild = 1
      if(whichchild):  otherchild = 0
      if(children[whichchild]=='boy'):
        firstpickwasboy[children[otherchild]] += 1
      else:
        firstpickwasgirl[children[otherchild]] += 1
    
    >>> firstpickwasboy
    {'boy': 25132, 'girl': 25116}
    >>> firstpickwasgirl
    {'boy': 24679, 'girl': 25073}
Re:The question is wrong by peakok on Saturday January 03, 2009 @08:11PM (#418836)
I'm willing to bet $5 that the probability (according to the current statistical science corpus) is still 2/3 (even if you're right that announcing the child doesn't alter the sex of the other). See my comment in the main thread.
Re:The question is wrong by paul on Saturday January 03, 2009 @08:27PM (#418852)
I'll take that bet. Write the code, but be careful to implement my second algorithm exactly.
Re:The question is wrong by peakok on Saturday January 03, 2009 @09:23PM (#418894)
Ok this thread is confusing. Actually, your second algorithm wasn't the point of my argument. You're right that according to your second formulation, the probability is 1/2, of course.

My point is that there is nothing wrong with Jeff's question, and I believed that you made a distinction with the Monty Hall version. But your second algorithm isn't the same as Jeff's question, my mistake.

It is very clear that my argument specifically adresses the question the way Jeff has formulated it, so you can even forget the part about "your second formulation", what I meant was the question of Jeff and why there is nothing wrong with it.

In statistics, it is commonly accepted that we don't know what we don't state (for an obvious practical purpose). Therefore, when we say : "One of them is a girl", it is implied that we don't know wich one because we didn't specify it.

Therefore there is nothing wrong with Jeff's question (and the probability is 2/3), at least for anyone familiar with basic statistics and probabilities conventions (and I suspect you are), anything else is just quibble. I assumed your argument wasn't about nitpicking this kind of convention, but it turns out I was wrong. I guess nobody wins this one :)

Re:The question is wrong by randallsquared on Saturday January 03, 2009 @09:32PM (#418899)
This hinges on whether we decided ahead of time that we would only consider cases in which there is a girl, something which I didn't see earlier. :)

As mentioned in another thread started by Eliezer, it's the difference between "What is the sex of one of your children?" and "Is (at least) one of your children a girl?". For the second question, the results skew to 1/3 and 2/3 because we're discarding the cases where the answer is 'no'.

The light went on for me when Paul pointed out in his update that getting a random answer for "What is the sex of one of your children?" eliminates (an unknown) one of BG and GB.

Re:The question is wrong by peakok on Saturday January 03, 2009 @10:27PM (#418941)
Basically you're right, and Paul is right too. This is just a matter of convention, it depends on what you want to hear in the question. If Jeff said "one of the children is a girl", but added "but we don't know wich one of the two is", this post would have never existed and we wouldn't have argued so much over nothing.

In the world of mathematical conventions you learn in school, the question is understood and you're right. In the "normal" world where you can quibble with language because there is no specific agreement, Paul is right and the question should be more precise. In both cases the conclusion remains the same : what a waste of time.