"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?]
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.
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.
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:
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?]