>>11073837>I have N boxes and N apples. I select one box at random, regardless of how many it already contains, and put one apple in it. Repeat until all apples are in a box. I then sort the boxes in increasing order by number of apples they contain.So I wrote a short program that does exactly this
>On average, what fraction of the total number of boxes remain empty On average, 37% of the boxes remain empty. The experiment was performed 10,000 times.
> as a function of N, and what does this value approach as N goes to infinity?Seems like it's 37%.
N = 100, results in 36.5%
N = 5000 results in 36.7%
>On average, how many apples will be in the box with the most applesN = 100, approximately 4 apples on average in the biggest box
N = 1000, approximately 5 apples on average in the biggest box
N = 10000, approximately 6 apples on average in the biggest box
Not sure if code tags work here
[code:lit]
import random
def run_experiment_empty(n):
boxes = [0] * n
for ii in range(0,n):
boxes[random.randint(0,n-1)] += 1
return (boxes.count(0) / len(boxes))
def run_experiment_max(n):
boxes = [0] * n
for ii in range(0,n):
boxes[random.randint(0,n-1)] += 1
return (max(boxes))
def get_average_empty(repeat, n):
results = []
for ii in range(0,repeat):
results.append(run_experiment_empty(n))
return (sum(results) / len(results))
def get_average_max(repeat, n):
results = []
for ii in range(0,repeat):
results.append(run_experiment_max(n))
return (sum(results) / len(results))
print(get_average_empty(1000, 100)) #N = 100, repeat 1,000 times
print(get_average_max(1000, 100))
[/code:lit]