Datasets:
File size: 678 Bytes
93237a0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | from fractions import Fraction as F
segments = [(F(15), F(25), F(1, 5), F(0)),
(F(25), F(35), F(0), F(5)),
(F(35), None, F(1, 5), F(-2))]
b_speed, b_offset = F(3, 10), F(-9, 2)
meetings = []
for lo, hi, a_speed, a_offset in segments:
t = (b_offset - a_offset) / (a_speed - b_speed)
if t >= lo and (hi is None or t <= hi):
meetings.append(t)
t = min(meetings)
seconds = t * 60
assert seconds.denominator == 1
position = b_speed * t + b_offset
result = {"seconds_after_A": int(seconds), "seconds_after_B": int(seconds - 900),
"distance_km": str(position)}
import json
print(json.dumps(result, ensure_ascii=False, sort_keys=True))
|