Guest User

Untitled

a guest
Jan 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import random
  2.  
  3. def completeCollection(n):
  4. #collects random "coupons"
  5. #in range 0,1,...,n-1
  6. #until each is encountered at least once
  7. #returns the list of counts
  8.  
  9. counts = [0]*n
  10. collected = set()
  11. while len(collected) < n:
  12. coupon = random.randint(0,n-1)
  13. counts[coupon] += 1
  14. collected.add(coupon)
  15. return counts
  16.  
  17. def expectedMax(n,trials):
  18. #estimates the number of times
  19. #the most collected coupon is
  20. #collected while collecting n coupons
  21. count = 0
  22. for i in range(trials):
  23. count += max(completeCollection(n))
  24. return count/trials
  25.  
  26. import random
  27.  
  28. def completeCollection(n):
  29. #collects random "coupons"
  30. #in range 0,1,...,n-1
  31. #until each is encountered at least once
  32. #returns the list of counts
  33.  
  34. counts = [0]*n
  35. collected = set()
  36. while len(collected) < n:
  37. coupon = random.randint(0,n-1)
  38. counts[coupon] += 1
  39. collected.add(coupon)
  40. return counts
  41.  
  42. def expectedMax(n,trials):
  43. #estimates the number of times
  44. #the most collected coupon is
  45. #collected while collecting n coupons
  46. count = 0
  47. for i in range(trials):
  48. count += max(completeCollection(n))
  49. return count/trials
  50.  
  51. [1.0, 1.985, 2.79, 3.403, 4.052, 4.575, 4.784, 5.145, 5.45, 5.672, 6.008, 6.198, 6.515, 6.508, 6.765, 7.006, 7.074, 7.207, 7.466, 7.416, 7.534, 7.711, 7.812, 7.992, 8.049, 8.012, 8.268, 8.467, 8.408, 8.467, 8.604, 8.54, 8.779, 8.666, 8.804, 9.121, 9.076, 9.033, 9.179, 9.289, 9.344, 9.33, 9.479, 9.456, 9.601, 9.613, 9.644, 9.836, 9.693, 9.82, 9.886, 9.944, 10.044, 10.124, 10.161, 10.113, 10.039, 10.273, 10.334, 10.345, 10.317, 10.454, 10.519, 10.483, 10.491, 10.496, 10.617, 10.593, 10.719, 10.859, 10.885, 10.782, 10.858, 10.841, 10.87, 10.804, 11.005, 11.005, 10.993, 11.105, 11.092, 11.121, 11.106, 11.159, 11.198, 11.209, 11.291, 11.393, 11.444, 11.428, 11.395, 11.584, 11.533, 11.511, 11.545, 11.559, 11.601, 11.585, 11.61,11.617]
Add Comment
Please, Sign In to add comment