Depends a bit on assumptions, but it's not quite what I expected, actually:
import math
import random
B = 1000
elevators = [-6, 0, 3]
def time_to_enter_distribution(position):
for _ in range(0, B):
elevator = random.choice(elevators)
distance = elevator - position
# What matters is not how many people are in the elevator, but how
# quickly they can evacuate. Approximate Poisson distribution.
evac_time = [0, 1, 2, 3, 3, 4, 5][random.randint(0, 6)]
# While you walk to the elevator, you give time for people to evacuate
# and your time passes.
evac_time -= abs(distance)
time = abs(distance)
# If people are still evacuating when you have arrived, you have to wait
# for that to end by the side of the elevator, and then take the final
# 0.5 metres to step inside.
if evac_time > 0:
time += evac_time + 0.5
yield time
def time_to_enter_summary(position):
distr = list(time_to_enter_distribution(position))
sum_time = sum(distr)
sum_sq_time = sum(t**2 for t in distr)
mean = sum_time/B
sd = (sum_sq_time - sum_time**2/B)/(B-1)
se = sd/math.sqrt(B)
return (mean, se)
if __name__ == '__main__':
print(f'{"pos":5s} {"t":4s} {"se":3s}')
for p in (i/4 for i in range(-6*4, 3*4)):
(t, se) = time_to_enter_summary(p)
print(f'{p:5.2f}: {t:4.2f} ({se:3.2f})')