-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.py
More file actions
29 lines (27 loc) · 834 Bytes
/
temp.py
File metadata and controls
29 lines (27 loc) · 834 Bytes
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
import random as rand
from datetime import datetime as dt
rand.seed(dt.now().timestamp())
totalDistance = 0
optimumDistance = 0
total = 0
truth = [1, 2, 3, 4, 5]
try:
for j in range(0, 1000000):
test = rand.sample(range(1, 6), 5)
for i in range(0, 5):
totalDistance += abs(i - test.index(truth[i]))
optimumDistance += test.index(truth[0])
total += 1
print(total)
# print(test, totalDistance, optimumDistance)
# exit()
raise
except:
print(f"Out of {total} tries:")
print(
f"Average total distance: {round(totalDistance/total, 1)}, total distance: {totalDistance}"
)
print(
f"Average optimum distance: {round(optimumDistance/total, 1)}, total optimum distance: {optimumDistance}"
)
exit()