4 ms·
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
by paul 18y ago
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.
- randallsquared 18y agoThe 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}
- deleted 18y ago[deleted]
- deleted 18y ago[deleted]
- nostrademons 18y agoI 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.