Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import sample
- from collections import defaultdict
- tests = 100000
- population = range(25)
- weeks = defaultdict(int)
- for _ in range(tests):
- A = 25*[0]
- B = 25*[0]
- week = 0
- while sum(B)<25:
- sam = sample(population, 2)
- for s in sam:
- if A[s] == 0:
- A[s] = 1
- elif B[s] == 0:
- B[s] = 1
- week +=1
- weeks[week] += 1
- expect = sum(k*weeks[k] for k in weeks)/tests
- print(tests, 'trials')
- print('Mean number of weeks', expect)
- for n in range(50, 175, 25):
- p = sum(weeks[k] for k in weeks if k > n)/tests
- print('Prob of more than %d weeks: %s'%(n,p))
- 100000 trials
- Mean number of weeks 70.20713
- Prob of more than 50 weeks: 0.91649
- Prob of more than 75 weeks: 0.3142
- Prob of more than 100 weeks: 0.05515
- Prob of more than 125 weeks: 0.00849
- Prob of more than 150 weeks: 0.00133
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement