Created
March 28, 2012 23:42
-
-
Save tshddx/2231556 to your computer and use it in GitHub Desktop.
What are the odds of, in a set of X people, there being at least Y people who share a birthday?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Thomas Shaddox | |
# https://github.com/baddox | |
# Assumes birthdays are independent (i.e. uniformly distributed) | |
days = 365 | |
ppl = 290 # I'm so popular | |
trials = 10_000 | |
at_least_four = 0 | |
trials.times do | |
array = [0] * days | |
ppl.times do | |
day = (rand() * days).truncate | |
array[day] += 1 | |
end | |
at_least_four += 1 if array.max >= 4 | |
end | |
puts "Probability of at least 4 shared birthdays is #{(at_least_four / trials.to_f) * 100}%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment