Created
September 6, 2013 18:06
-
-
Save eriktaubeneck/6467599 to your computer and use it in GitHub Desktop.
Simulation for determining the probability of `same_dbday` people having the same birthday out of a group of sized `people`. Assumes all days are equally likely and ignores leap years, but it's a 23 line Julia script so whatever. Happy Birthday @alexandrinaw and @alisaex!
This file contains hidden or 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
using Distributions | |
people = 88 | |
same_bday = 3 | |
days = 365 | |
trials = 1000000 | |
success = 0 | |
for i = 1:trials | |
bday_d = Distributions.DiscreteUniform(1,days) | |
bdays = rand(bday_d,people) | |
for bday in bdays | |
same_bdays = 0 | |
for bday2 in bdays | |
if bday == bday2 | |
same_bdays += 1 | |
end | |
end | |
if same_bdays >= 3 | |
success += 1 | |
break | |
end | |
end | |
end | |
print(success/trials) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment