bilingual-math-code-verification-v1 / code /math_code_012_solution.py
efe-T's picture
Upload folder using huggingface_hub
93237a0 verified
Raw History Blame Contribute Delete
678 Bytes
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))