Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. from random import sample
  2. from collections import defaultdict
  3.  
  4. tests = 100000
  5. population = range(25)
  6.  
  7. weeks = defaultdict(int)
  8. for _ in range(tests):
  9. A = 25*[0]
  10. B = 25*[0]
  11. week = 0
  12. while sum(B)<25:
  13. sam = sample(population, 2)
  14. for s in sam:
  15. if A[s] == 0:
  16. A[s] = 1
  17. elif B[s] == 0:
  18. B[s] = 1
  19. week +=1
  20. weeks[week] += 1
  21.  
  22. expect = sum(k*weeks[k] for k in weeks)/tests
  23. print(tests, 'trials')
  24. print('Mean number of weeks', expect)
  25. for n in range(50, 175, 25):
  26. p = sum(weeks[k] for k in weeks if k > n)/tests
  27. print('Prob of more than %d weeks: %s'%(n,p))
  28.  
  29. 100000 trials
  30. Mean number of weeks 70.20713
  31. Prob of more than 50 weeks: 0.91649
  32. Prob of more than 75 weeks: 0.3142
  33. Prob of more than 100 weeks: 0.05515
  34. Prob of more than 125 weeks: 0.00849
  35. Prob of more than 150 weeks: 0.00133
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement