Created
April 24, 2012 14:59
-
-
Save bgnori/2480308 to your computer and use it in GitHub Desktop.
birthday collision in twitter, with 500 followers.
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
import random | |
def experiment(): | |
bds = {} | |
for n in range(500): | |
bd = random.randint(1, 365) | |
bds[bd] = bds.get(bd, 0) + 1 | |
result = {} | |
for i in range(1, 366): | |
if i in bds and bds[i] > 1: | |
x = result.get(bds[i], None) | |
if x is None: | |
x = [i] | |
else: | |
x.append(i) | |
result[bds[i]] = x | |
return result | |
#print experiment() | |
stat = {} | |
for i in range(1000): | |
r = experiment() | |
for k, v in r.items(): | |
x = stat.get(k, 0) | |
stat[k] = x + len(v) | |
for k,v in stat.items(): | |
print k, v/1000.0 | |
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
[nori@akagi]~/Desktop/study/python/junk% python birthday.py | |
2 87.241 | |
3 39.955 | |
4 13.566 | |
5 3.718 | |
6 0.818 | |
7 0.148 | |
8 0.03 | |
9 0.002 | |
[nori@akagi]~/Desktop/study/python/junk% python birthday.py | |
2 86.802 | |
3 40.035 | |
4 13.499 | |
5 3.7 | |
6 0.812 | |
7 0.165 | |
8 0.043 | |
9 0.004 | |
10 0.001 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(12/04/24 23:47) [$lz] bgnori: 500人もフォロワがいたら、同じ誕生日の人は何人いるだろう? Termtter
(12/04/24 23:53) [$ma] bgnori: 500人いると、誕生日が6人とかぶつかっている可能性が充分ある。 Termtter
(12/04/24 23:57) [$mb] bgnori: ruby病 pythonで()をつけ忘れる Termtter
(12/04/25 00:00) [$mc] bgnori: くだらないコードを書いてしまった。500人のフォロアで誕生日がどのくらい衝突しているか。 https://gist.github.com/2480308 Termtter