4 ms·
How about this: People shoot in a random order (now everyone has the same chance of making it to the next round. Is it 1/e?) import numpy as np class Shoo
by boyobo 7y ago
How about this: People shoot in a random order (now everyone has the same chance of making it to the next round. Is it 1/e?)
import numpy as np
class Shooter:
def __init__(self):
self.dead = False
self.right = None # The person to the right
def simulate(n):
# Simulates a round with n shooters
# Returns the ratio of survivors
shooters = [Shooter() for i in range(n)]
for i, shooter in enumerate(shooters):
shooter.right = shooters[(i+1) % len(shooters)]
np.random.shuffle(shooters)
HIT_PROBABILITY = 1/6
survivors = n
for shooter in shooters:
if not shooter.dead:
if np.random.random() < HIT_PROBABILITY:
shooter.right.dead = True
survivors = survivors - 1
return survivors/n
Simulations suggest that the survival probabilities do not converge to 6/7 if you add shuffling. This makes sense, since the survival probability for the random shuffling version must be strictly less than if you are guaranteed to go first.
>>>sum([simulate(10000) for j in range(1000)])/1000
0.8463075999999998