Skip to content

Instantly share code, notes, and snippets.

@gwy15
Created April 3, 2019 03:25
Show Gist options
  • Save gwy15/812b5fef928f40104935868c8c802de5 to your computer and use it in GitHub Desktop.
Save gwy15/812b5fef928f40104935868c8c802de5 to your computer and use it in GitHub Desktop.
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