让我们将 A 表示为 Alice 翻转硬币的次数,将 B 表示为 Bob 翻转硬币的次数。我们给出了条件 A<B。找到 P(A<B) 后,我们就可以形成条件期望。通过对称性 P(A<B)=P(B<A),我们可以看到:
P(A<B)=21−P(A=B)
有机会 21⋅21 两个硬币都翻转一次,41⋅41 两次,81⋅81 三次,依此类推。因此,
P(A=B)=41+161+641...
→4P(A=B)=1+41+161+641...
从底部减去顶部我们可以看到:
3P(A=B)=1
→P(A=B)=31
使用它我们计算:
P(A<B)=21−31=31
我们现在可以计算 P(A=n∣A<B)。如果爱丽丝抛硬币一次,我们知道她在第一次抛硬币时一定会得到正面,而鲍勃在第一次抛硬币时一定会得到反面。如果她掷硬币两次,她会得到正面,然后是反面,而鲍勃在前两次抛硬币时会得到反面,依此类推。我们的有条件期望:
E[A∣A<B]=3121⋅21(1)+3141⋅41(2)+3181⋅81(3)...=43(1)+163(2)+643(3)...
=43(1)+163(2)+643(3)...
我们可以将 4E[A∣A<B]−E[A∣A<B] 计算为:
4E[A∣A<B]=3(1)+43(2)+163(3)+643(4)...
4E[A∣A<B]−E[A∣A<B]=3E[A∣A<B]=3+43+163+643...
同样我们计算:
12E[A∣A<B]=12+3+43+163+643...
12E[A∣A<B]−3E[A∣A<B]=9E[A∣A<B]=12
⟹E[A∣A<B]=34
import random
flip_coin = lambda: True if random.randint(1,2) == 1 else False
alice_flip_counts = []
num_iters = 100_000
for i in range(num_iters):
alice_flips = 0
while(True):
bob_flips_heads = flip_coin()
if bob_flips_heads:
break
alice_flips += 1
alice_flips_heads = flip_coin()
if alice_flips_heads:
alice_flip_counts.append(alice_flips)
break
print(sum(alice_flip_counts) / len(alice_flip_counts))
Original Explanation
Let's denote A as the number of times Alice flips her coin and B the number of times Bob flips his coin. We are given the condition A<B. Upon finding P(A<B) we can form our conditional expectations. By symmetry P(A<B)=P(B<A) so we see that:
P(A<B)=21−P(A=B)
There is a 21⋅21 chance both coins are flipped once, 41⋅41 twice, 81⋅81 three times and so on. Thus,
P(A=B)=41+161+641...
→4P(A=B)=1+41+161+641...
Subtracting the top from bottom we see:
3P(A=B)=1
→P(A=B)=31
Using this we compute:
P(A<B)=21−31=31
We can now compute P(A=n∣A<B). If Alice flips her coin once, we know that she must get a heads on the first flip and Bob must get a tails on his first flip. If she flips her coin twice, she gets a heads followed by tails and Bob gets tails for his first two flips and so on. Our conditional expectations:
E[A∣A<B]=3121⋅21(1)+3141⋅41(2)+3181⋅81(3)...=43(1)+163(2)+643(3)...
=43(1)+163(2)+643(3)...
We can compute 4E[A∣A<B]−E[A∣A<B] as:
4E[A∣A<B]=3(1)+43(2)+163(3)+643(4)...
4E[A∣A<B]−E[A∣A<B]=3E[A∣A<B]=3+43+163+643...
Similarly we compute:
12E[A∣A<B]=12+3+43+163+643...
12E[A∣A<B]−3E[A∣A<B]=9E[A∣A<B]=12
⟹E[A∣A<B]=34
import random
flip_coin = lambda: True if random.randint(1,2) == 1 else False
alice_flip_counts = []
num_iters = 100_000
for i in range(num_iters):
alice_flips = 0
while(True):
bob_flips_heads = flip_coin()
if bob_flips_heads:
break
alice_flips += 1
alice_flips_heads = flip_coin()
if alice_flips_heads:
alice_flip_counts.append(alice_flips)
break
print(sum(alice_flip_counts) / len(alice_flip_counts))