Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def completeCollection(n):
- #collects random "coupons"
- #in range 0,1,...,n-1
- #until each is encountered at least once
- #returns the list of counts
- counts = [0]*n
- collected = set()
- while len(collected) < n:
- coupon = random.randint(0,n-1)
- counts[coupon] += 1
- collected.add(coupon)
- return counts
- def expectedMax(n,trials):
- #estimates the number of times
- #the most collected coupon is
- #collected while collecting n coupons
- count = 0
- for i in range(trials):
- count += max(completeCollection(n))
- return count/trials
- import random
- def completeCollection(n):
- #collects random "coupons"
- #in range 0,1,...,n-1
- #until each is encountered at least once
- #returns the list of counts
- counts = [0]*n
- collected = set()
- while len(collected) < n:
- coupon = random.randint(0,n-1)
- counts[coupon] += 1
- collected.add(coupon)
- return counts
- def expectedMax(n,trials):
- #estimates the number of times
- #the most collected coupon is
- #collected while collecting n coupons
- count = 0
- for i in range(trials):
- count += max(completeCollection(n))
- return count/trials
- [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