Skip to content

Instantly share code, notes, and snippets.

@rkhapov
Last active October 10, 2015 04:09
Show Gist options
  • Save rkhapov/63aa1f1850c897e42fdd to your computer and use it in GitHub Desktop.
Save rkhapov/63aa1f1850c897e42fdd to your computer and use it in GitHub Desktop.
Решение задачи с урока 03.10.15
import math
def sqr(a):
return a*a
def compute_distance(x1, y1, x2, y2):
return math.sqrt(sqr(x2 - x1) + sqr(y2 - y1))
try:
fp = open("file.data", "r")
except OSError:
print("Cann't open file.data")
exit(1)
file_data = fp.readlines()
max_local_veocity = 0.0
summ_distance = 0.0
prev_x, prev_y, last_time = list(map(float, file_data[0].split()))
for i in range(1, len(file_data)):
x, y, t = list(map(float, file_data[i].split()))
summ_distance += compute_distance(prev_x, prev_y, x, y)
max_local_veocity = max(max_local_veocity, compute_distance(prev_x, prev_y, x, y) / (t - last_time))
prev_x = x
prev_y = y
last_time = t
print("Max local velocity: " + str(max_local_veocity))
print("Avarage speed: " + str(summ_distance / last_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment