-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.py
More file actions
49 lines (38 loc) · 1.06 KB
/
Source.py
File metadata and controls
49 lines (38 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import array
import random
import matplotlib.pyplot as plt
#"complexity equals to iterations * balls"
iterations = 50
boxes = 100
balls = 1000000
box = [0.0] * boxes #"actual result is here"
temp_box = [0] * boxes
#"box have to be initialized as zeroes here"
#"if it's not"
def throw_balls():
#"temp_box = 0" "have to be done every time"
for i in range(boxes):
temp_box[i] = 0
#"maybe, like that"
for i in range(balls):
tmp = random.randrange(boxes)
temp_box[tmp] += 1
def demo():
for i in range(iterations):
throw_balls()
#"sort temp_box"
list.sort(temp_box, reverse=True)
for j in range(boxes):
box[j] = (box[j] * i + temp_box[j]) / (i + 1)
axes = plt.gca()
axes.set_ylim([0, box[0]])
plt.xlabel('x')
plt.ylabel('y')
plt.plot(range(boxes), box, color="red")
plt.plot(range(boxes), [balls/boxes]*boxes, color="green")
plt.show()
if __name__ == '__main__':
demo()
print(box[5])
#"it's, actually, time for drawings"
#"have no idea about how to do it"