Problem
In a buildingβs lobby, some number of people get on an elevator that goes to some number of floors. There may be more people than floors, or more floors than people. Each person is equally likely to choose any floor, independently of one another. When a floor button is pushed, it will light up. What is the expected number of lit buttons when the elevator begins its ascent?
Solution
Let be the random variable indicating the number of lit buttons where is the indicator random variable which is when at least person chooses floor and otherwise.
where is the probability of no one selecting floor .
Therefore .
Computational verification
from random import random, choice
from collections import Counter
n, m = 30, 20
runs = 10000
total_lit = 0
for _ in range(runs):
choices = [choice(range(m)) for _ in range(n)]
num_lit = sum([1 if c > 0 else 0 for l, c in Counter(choices).items()])
total_lit += num_lit
print(total_lit/runs)