3 ms·
The best real-world optimization: stand aside to make room for anyone exiting the elevator before crowding the doorway trying to walk in too quickly!
by glitcher 4y ago
The best real-world optimization: stand aside to make room for anyone exiting the elevator before crowding the doorway trying to walk in too quickly!
- novosel 4y agoOh my god, this.
- GuB-42 4y agoGreat, you just made the problem more complicated. That's is because if there are people in the elevator and you right in front of it, you have to move away, wait, and go back. Not ideal, it makes more sense to wait on the side of the elevator, possibly at a distance proportional to the expected time it takes for the passengers to leave. That would make the ideal waiting spot somewhere between the middle elevator and the other one that is the furthest away from the middle elevator, but not necessarily the mean.
- kqr 4y agoDepends 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})')