A help desk receives messages at random moments, independently of each other, on average rate messages per hour. A volunteer covers a shift of minutes minutes and wants to know how many messages to expect.
Write message_table(rate, minutes, kmax) that returns a list of kmax + 2 floats: the probabilities that exactly 0, 1, ..., kmax messages arrive during the shift, followed by the probability that more than kmax arrive.
Examples
Input: rate = 6, minutes = 20, kmax = 3
Output: [0.1353352832366127, 0.2706705664732254, 0.2706705664732254, 0.18044704431548358, 0.14287653950145285]
Explanation: 6 per hour is 2 per 20 minutes. P(0) = e^-2 = 0.1353, P(1) = e^-2 · 2 = 0.2707,
P(2) = e^-2 · 4 / 2 = 0.2707, P(3) = e^-2 · 8 / 6 = 0.1804, and 1 minus their sum is 0.1429.
Input: rate = 12, minutes = 15, kmax = 0
Output: [0.049787068367863944, 0.950212931632136]
Constraints
0 < rateand0 < minutes, withrate * minutes / 60 <= 1000 <= kmax <= 150- floats are compared with a tolerance of
1e-6
Goals
- Scale an hourly rate to the length of a time window
- Compute Poisson probabilities with math.exp and math.factorial
- Collect the remaining probability in a tail entry with the complement rule