-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (52 loc) · 1.69 KB
/
main.py
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
from bokeh.plotting import figure, output_file, show
import random
# Array of coordinates (x,y)
x_values = []
y_values = []
# Main function of Random Walks
def main(steps, reps):
path = []
distances = []
def random_walks(steps):
x = 0
y = 0
for i in range (steps):
step = random.choice(['UP','DOWN','LEFT','RIGHT'])
if step == 'UP':
y += 1
elif step == 'DOWN':
y -= 1
elif step == 'LEFT':
x -= 1
else:
x += 1
return (x,y)
# Loop of n repetitions and n steps
for i in range(reps):
walk = random_walks(steps)
print(walk, "Distance from home = ", abs(walk[0]) + abs(walk[1]))
distance = abs(walk[0]) + abs(walk[1])
distances.append(distance)
x_values.append(walk[0])
y_values.append(walk[1])
path.append(walk)
min_distance = min(distances)
max_distance = max(distances)
distances_length = len(distances)
distances_sum = 0
for i in distances:
distances_sum += i
avg_distance = int(distances_sum / distances_length)
print(path)
print(f'Minimun distance: {min_distance}')
print(f'Maximun distance: {max_distance}')
print(f'average distance: {avg_distance}')
return x_values,y_values
if __name__ == "__main__":
number_steps = int(input('How many steps do you want to walk: '))
number_reps = int(input('How many reps do you want to do: '))
main(number_steps, number_reps)
output_file('simple__graphic.html')
figure = figure()
figure.line(x_values, y_values, line_width=2)
show(figure)