Created
March 25, 2017 15:02
-
-
Save telliott99/e323790f1b3d31a0ef7ab72e03c62b77 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) - 2: # 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 | |
n = j - i | |
if n in rD: | |
rD[n] += 1 | |
else: | |
rD[n] = 1 | |
i = j + 1 | |
return rD | |
#---------------------------------- | |
# run the simulation for my case: 45 friends | |
N = 45 | |
D = dict() | |
reps = 1000 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment