-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrog.py
More file actions
96 lines (73 loc) · 1.85 KB
/
Copy pathfrog.py
File metadata and controls
96 lines (73 loc) · 1.85 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'''
random walk, where every step is randomly jumping between current position and the end.
'''
import random
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("darkgrid")
# parameters
end_pos = 500
max_reps = 100
# Here, we do max_reps of a river of length end_pos
# container for results
count = []
# loop
for x in range(max_reps):
current_pos = 0
steps = 0
while current_pos < end_pos:
current_pos = random.randint(current_pos + 1, end_pos + 1)
steps = steps + 1
count.append(steps)
print('Average of', len(count), 'jumps is', sum(count) / len(count))
# print(count)
# Here, we fix the length of the river at end_pos, and increase
# repetitions upto max_reps
# containers for graphs
n = []
mean1 = []
temp_1 = 1
while temp_1 < max_reps:
# container for results
count = []
# loop
for temp_2 in range(temp_1):
current_pos = 0
steps = 0
while current_pos < end_pos:
current_pos = random.randint(current_pos + 1, end_pos + 1)
steps = steps + 1
count.append(steps)
mean1.append(sum(count) / len(count))
n.append(temp_1)
temp_1 = temp_1 + 1
plt.figure()
plt.legend(
plt.plot(n, mean1),
['Increasing repetitions']
)
# plt.show()
# Here, we do max_reps of rivers of increasing width, upto end_pos
# containers for graphs
length = []
mean2 = []
temp_1 = 1
for temp_1 in range(end_pos):
# container for results
count = []
# loop
for temp_2 in range(max_reps):
current_pos = 0
steps = 0
while current_pos < temp_1:
current_pos = random.randint(current_pos + 1, temp_1 + 1)
steps = steps + 1
count.append(steps)
mean2.append(sum(count) / len(count))
length.append(temp_1)
plt.figure()
plt.legend(
plt.plot(length, mean2),
['Increasing n']
)
# plt.show()