Skip to content

Instantly share code, notes, and snippets.

@eriktaubeneck
Created September 6, 2013 18:06
Show Gist options
  • Save eriktaubeneck/6467599 to your computer and use it in GitHub Desktop.
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!
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