Created
April 3, 2019 03:25
-
-
Save gwy15/812b5fef928f40104935868c8c802de5 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
import random | |
probs = [1.2, 1.2, 1.1, 1.05, 1.5, 1.75, 2.0, 1.7] | |
probs.append(100 - sum(probs)) | |
populations = list(range(len(probs))) | |
def getTime(): | |
time = 0 | |
collected = [False for key in populations] | |
while True: | |
time += 1 | |
choice = random.choices(populations, weights=probs, k=1)[0] | |
collected[choice] = True | |
if sum(collected[:8]) >= 6: | |
return time | |
ts = [] | |
N = 100_000 | |
for i in range(N): | |
ts.append(getTime()) | |
print(sum(ts) / N) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment