OnePump2Stroke
2020-06-07T11:51:38+00:00
答案是13/27,我要看看这个论坛平均学历到底是多少[s:ac:哭笑]
附上python暴力解法
def IsTwoBoys(rand):
genders = ('M', 'F')
weekdays = tuple(range(1, 8))
while True:
children = [(rand.choice(genders), rand.choice(weekdays)) for i in xrange(2)]
if ((children[0][0] == 'M' and children[0][1] == 2) or
(children[1][0] == 'M' and children[1][1] == 2)):
return True if children[0][0] == children[1][0] == 'M' else False
cnt = 1000000
twoboys = 0
rand = Random()
for i in xrange(cnt):
if IsTwoBoys(rand):
twoboys += 1
print 'p(twoboys) =', twoboys, '/', cnt, '=', float(twoboys) / cnt
最后结果0.48213
附上python暴力解法
def IsTwoBoys(rand):
genders = ('M', 'F')
weekdays = tuple(range(1, 8))
while True:
children = [(rand.choice(genders), rand.choice(weekdays)) for i in xrange(2)]
if ((children[0][0] == 'M' and children[0][1] == 2) or
(children[1][0] == 'M' and children[1][1] == 2)):
return True if children[0][0] == children[1][0] == 'M' else False
cnt = 1000000
twoboys = 0
rand = Random()
for i in xrange(cnt):
if IsTwoBoys(rand):
twoboys += 1
print 'p(twoboys) =', twoboys, '/', cnt, '=', float(twoboys) / cnt
最后结果0.48213