Created
August 30, 2012 23:13
-
-
Save jbarratt/3544458 to your computer and use it in GitHub Desktop.
How many birthdays/day as a function of your friend list size?
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
#!/usr/bin/env python | |
import sys | |
import random | |
friends = int(sys.argv[1]) | |
counts = {} | |
iterations = 1000 | |
def bday_per_day(): | |
days = {} | |
for friend in range(0, friends): | |
day = random.randint(1, 365) | |
days[day] = days.get(day, 0) + 1 | |
for day in range(1, 366): | |
birthdays = days.get(day, 0) | |
counts[birthdays] = counts.get(birthdays, 0) + 1 | |
for run in range(0, iterations): | |
bday_per_day() | |
for count in sorted(counts, key=counts.get, reverse=True): | |
print "%d birthdays: %0.03f times/year" % ( | |
count, counts[count] / float(iterations)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ ./bdaydist.py 401
1 birthdays: 133.954 times/year
0 birthdays: 121.482 times/year
2 birthdays: 73.353 times/year
3 birthdays: 26.869 times/year
4 birthdays: 7.380 times/year
5 birthdays: 1.617 times/year
6 birthdays: 0.291 times/year
7 birthdays: 0.043 times/year
8 birthdays: 0.008 times/year
9 birthdays: 0.001 times/year