Created
April 2, 2017 12:49
-
-
Save telliott99/2df2e091ab7b36d663d7dfb4608b5440 to your computer and use it in GitHub Desktop.
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
from random import choice as ch | |
R = range(1,366) | |
# report doubles, triples for a single run | |
def analyze(L): | |
L.sort() | |
rD = dict() | |
i = 0 | |
while i < len(L) - 1: # up to penultimate item | |
v = L[i] | |
j = i + 1 | |
if L[j] != v: | |
i += 1 | |
continue | |
while j < len(L) and L[j] == v: | |
j += 1 | |
sz = j - i # length of repeat | |
if sz in rD: | |
rD[sz] += 1 | |
else: | |
rD[sz] = 1 | |
i = j + 1 | |
return rD | |
#---------------------------------- | |
# run the simulation for my case: 45 friends | |
N = 45 | |
D = dict() | |
reps = 10000 | |
for i in range(reps): | |
L = [ch(R) for i in range(N)] | |
rD = analyze(L) | |
s = str(rD) | |
if not s in D: | |
D[s] = 1 | |
else: | |
D[s] += 1 | |
#---------------------------------- | |
# print the results | |
revD = dict() | |
for k,v in D.items(): | |
revD[v] = k | |
c = len(str(reps)) | |
for k in sorted(revD.keys(), reverse=True): | |
print str(k).rjust(c), revD[k] | |
print reps | |
''' | |
> python friends.py | |
2727 {2: 2} | |
2251 {2: 3} | |
1934 {2: 1} | |
1138 {2: 4} | |
591 {} | |
396 {2: 5} | |
248 {2: 1, 3: 1} | |
220 {2: 2, 3: 1} | |
175 {2: 3, 3: 1} | |
85 {3: 1} | |
83 {2: 6} | |
60 {2: 4, 3: 1} | |
17 {2: 5, 3: 1} | |
13 {2: 7} | |
9 {2: 2, 3: 2} | |
7 {4: 1} | |
6 {3: 2} | |
5 {2: 1, 4: 1} | |
3 {2: 6, 3: 1} | |
2 {2: 3, 4: 1} | |
1 {5: 1} | |
10000 | |
> | |
''' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment