Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def run_test():
- global count, N
- def run_experiment(n_balls, n_cells, offset):
- cells = [0] * n_cells
- # toss balls randomly to cells:
- for j in range(n_balls):
- cells[random.randrange(0, n_cells)] += 1
- # cells[int(lines[offset + j])] += 1
- cells = sorted(cells)
- # print(cells)
- # check if there is an empty cell. if so return 0, otherwise 1:
- if cells[0] == 0:
- return 0
- return 1
- count = 0
- N = 1000000
- offset = 0
- N_CELLS = 8
- N_BALLS = 12
- # iterate experiment
- for i in range(N):
- result = run_experiment(N_BALLS, N_CELLS, offset=offset)
- count += result
- offset += N_CELLS
- print("probability:", count, "/", N, "(~", count / N, ")")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement