题目:
If, say, it is known that one of the children is a male born on a Tuesday, what is the probability of the other child to be also male?
分析:
什么鬼?周一到周日,每天都可以出生,还会影响孩子另一个孩子性别?
是的。
The sample space S = {ff, fm, mf, mm}, with f and m standing for “female: and “male”, respectively.
Denote these elementary events in sequence A1, A2, A3, A4.
他们的概率分别是 1/4, 1/4, 1/4, 1/4; P(Aj) = 1/4, j = 1, 2, 3, 4.
B 是男孩出生在周二的概率.
P(B|A1) = 0, 因为A1里面没有男孩.
P(B|A2) = P(B|A3) = 1/7, because in the two cases the one male bear has the probability 1/7 to have been born on any specific day, Tuesday in particular.
The most interesting case is A4. The following table is suggestive:
由图可知, P(B|A4) = 13/49.
P(A1|B), P(A2|B), P(A3|B), P(A4|B) 的概率分别是 0, 1/7, 1/7, 13/49,且应该被重新调节,已达到和为1.
按比例放大,得到P(A1|B) = 0, P(A2|B) = P(A3|B) = 1/7 ÷ 27/49 = 7/27,P(A4|B) = 13/49 ÷ 27/49 = 13/27.
所以周二出生的男孩的同胞为女性的概率为$ \frac{7}{27} \times 2 = \frac{14}{27}$.
因此火神作业将一周7天改为一年12个月,答案应该为:
$$\frac{\frac{1}{12}\times2}{(\frac{12\times2-1}{12\times12})+\frac{1}{12}\times2} = \frac{24}{47} = 0.5106$$
代码验证:
代码:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from random import randrange
results = {
"one_boy_born_tuesday":{"B": 0, "G": 0}, "one_boy":{"B": 0, "G": 0}, "first_is_boy":{"B": 0, "G": 0}, "first_is_boy_born_tuesday":{"B": 0, "G": 0}
}
for i in xrange(10000000):
house = []
for j in range(2):
sex = "B" if randrange(2) == 0 else "G"
day = randrange(7)
house.append({"sex":sex, "day":day})
exp = "one_boy_born_tuesday"
if (house[0]["sex"] == "B" and house[0]["day"] == 3):
results[exp][house[1]["sex"]] += 1
elif (house[1]["sex"] == "B" and house[1]["day"] == 3):
results[exp][house[0]["sex"]] += 1
exp = "one_boy"
if (house[0]["sex"] == "B"):
results[exp][house[1]["sex"]] += 1
elif (house[1]["sex"] == "B"):
results[exp][house[0]["sex"]] += 1
exp = "first_is_boy"
if (house[0]["sex"] == "B"):
results[exp][house[1]["sex"]] += 1
exp = "first_is_boy_born_tuesday"
if (house[0]["sex"] == "B" and house[0]["day"] == 3):
results[exp][house[1]["sex"]] += 1
for k, v in results.items():
print
print "-"*60
print k
print v
print 1.0*v["B"]/(v["G"]+v["B"])
对千万个孩子进行分析,结果应该很精准了!
运行结果:
------------------------------------------------------------
one_boy
{'B': 2498175, 'G': 5000766}
0.33313703895
------------------------------------------------------------
first_is_boy_born_tuesday
{'B': 356077, 'G': 357227}
0.499193892085
------------------------------------------------------------
first_is_boy
{'B': 2498175, 'G': 2500593}
0.499758140406
------------------------------------------------------------
one_boy_born_tuesday
{'B': 661673, 'G': 714128}
0.480936559866
完美!