Today I found an interesting revision of Avengers: Endgame. It says:
初代复仇者六人组,每人带一宝石手套,去找灭霸决战,到了草屋,七人围圈而坐,六对一,互相打响指意图消灭对方。灭霸人少,给予先打响指的权利,灭霸打后,超级英雄全化灰就灭霸胜,没全化灰就由一个活着的超级英雄打一个响指,看二分之一消失的概率能不能把灭霸打成灰。没成灰就继续第二回合,灭霸继续优先打响指。问灭霸死的概率是多少?
The original six avengers, each carrying a stone and fight with Thanos. Thanos snaps his fingers first and each avenger has a 50% probability to die. If all of the avengers die, thanos wins. If not, one of the alive avengers snap fingers and thanos has 50% percent to die. The fights will continue until one side wins. the question is: what is the probability of thanos death?
I still didn’t have a mathematical depict of the probability. But I simulate the data to find out the probability of Thanos’ death is about 80%.
Like Dr. Strange, I also find the result from 14000605 times test.
Refer to this repo
1 | import numpy as np |
Populating the interactive namespace from numpy and matplotlib
1 | np.random.randint(0,2,size=6) |
array([0, 1, 1, 1, 0, 0])
1 | def check_survive(input_num): |
1 | avengers_alive_num = 6 |
Round 1, avengers alive: 1, dead: 5
Thanos die first
1 | def summarize(avengers_alive_num = 6): |
1 | test_time = 14000605 |
HBox(children=(IntProgress(value=0, max=14000605), HTML(value='')))
1 | np.savetxt('summarize_data_num_6.txt',summarize_data.astype('uint8'),fmt='%1d') |
1 | fig,ax=plt.subplots(figsize=(8,4)) |
1 | fig,ax=plt.subplots(figsize=(8,4)) |
1 | print ('Avengers win {}, Thanos win {}'.format(1 - summarize_data[:,1].sum()/test_time,summarize_data[:,1].sum()/test_time) ) |
Avengers win 0.7940833985388489, Thanos win 0.20591660146115115
1 | unique_sum = np.unique(summarize_data[np.where(summarize_data[:,1]==0)][:,0],return_counts=1) |
win time | win probability | |
---|---|---|
1 | ||
1 | 6.89032e+06 | 0.492144 |
2 | 2.8789e+06 | 0.205627 |
3 | 964446 | 0.068886 |
4 | 281804 | 0.020128 |
5 | 75835 | 0.00541655 |
6 | 19639 | 0.00140273 |
7 | 4988 | 0.00035627 |
8 | 1274 | 9.09961e-05 |
9 | 331 | 2.36418e-05 |
10 | 91 | 6.49972e-06 |
11 | 17 | 1.21423e-06 |
12 | 5 | 3.57127e-07 |
13 | 1 | 7.14255e-08 |
1 | unique_sum = np.unique(summarize_data[np.where(summarize_data[:,1]==1)][:,0],return_counts=1) |
win time | win probability | |
---|---|---|
1 | ||
1 | 218176 | 0.0155833 |
2 | 1.13563e+06 | 0.0811129 |
3 | 948005 | 0.0677117 |
4 | 402860 | 0.0287745 |
5 | 128810 | 0.00920032 |
6 | 36483 | 0.00260582 |
7 | 9634 | 0.000688113 |
8 | 2508 | 0.000179135 |
9 | 660 | 4.71408e-05 |
10 | 147 | 1.04995e-05 |
11 | 27 | 1.92849e-06 |
12 | 11 | 7.8568e-07 |
13 | 5 | 3.57127e-07 |
14 | 1 | 7.14255e-08 |
It’s not fair! In fact, if there are only two avengers, the game will be more fair.
灭霸死的有点惨,其实复仇者初始只有两个人的时候概率稍微对等
1 | def summarize(avengers_alive_num = 6): |
1 | test_time = 14000605 |
HBox(children=(IntProgress(value=0, max=14000605), HTML(value='')))
1 | fig,ax=plt.subplots(2,1,figsize=(8,8)) |
1 | print ('Avengers win {}, Thanos win {}'.format(1 - summarize_data[:,1].sum()/test_time,summarize_data[:,1].sum()/test_time) ) |
Avengers win 0.523922359069483, Thanos win 0.4760776409305169
1 | unique_sum = np.unique(summarize_data[np.where(summarize_data[:,1]==0)][:,0],return_counts=1) |
win time | win probability | |
---|---|---|
1 | ||
1 | 5.25233e+06 | 0.37515 |
2 | 1.53058e+06 | 0.109322 |
3 | 409989 | 0.0292837 |
4 | 106393 | 0.00759917 |
5 | 26925 | 0.00192313 |
6 | 6764 | 0.000483122 |
7 | 1723 | 0.000123066 |
8 | 377 | 2.69274e-05 |
9 | 102 | 7.2854e-06 |
10 | 35 | 2.49989e-06 |
11 | 11 | 7.8568e-07 |
13 | 1 | 7.14255e-08 |
win time | win probability | |
---|---|---|
1 | ||
1 | 3.49891e+06 | 0.249911 |
2 | 2.18546e+06 | 0.156097 |
3 | 712026 | 0.0508568 |
4 | 199091 | 0.0142202 |
5 | 52039 | 0.00371691 |
6 | 13297 | 0.000949745 |
7 | 3438 | 0.000245561 |
8 | 816 | 5.82832e-05 |
9 | 215 | 1.53565e-05 |
10 | 65 | 4.64266e-06 |
11 | 17 | 1.21423e-06 |
12 | 5 | 3.57127e-07 |
13 | 1 | 7.14255e-08 |
1 | print ('Avengers win {}, Thanos win {}'.format(1 - summarize_data[:,1].sum()/test_time,summarize_data[:,1].sum()/test_time) ) |
Avengers win 0.523922359069483, Thanos win 0.4760776409305169
1 | np.savetxt('summarize_data_num_2.txt',summarize_data.astype('uint8'),fmt='%1d') |