Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-263

Birthday Exactly One Shared Birthday

Problem

Poisson approximation for the probability of exactly one shared birthday among n people when days birthdays are equally likely. Treat the number of colliding pairs as Poisson with mean lambda = n * (n - 1) / (2 * days) and return lambda * exp(-lambda). Return 0.0 for n < 2 or days <= 0.

Hint

With lambda colliding pairs on average, exactly one pair occurs with probability lambda * exp(-lambda).

Test cases

case 1
in: [23,365]
expected: 0.3465741279391074
case 2
in: [2,365]
expected: 0.002732230201635231
case 3
in: [57,365]
expected: 0.05517505581177928
case 4
in: [10,365]
expected: 0.1089874506486353
case 5
in: [1,365]
expected: 0
Starter codePython
import math


def birthday_exactly_one_collision(n, days):
    # Your code here
    pass

5 test cases · run your code against them in the editor