You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
656 B
Python
29 lines
656 B
Python
3 years ago
|
import re
|
||
|
|
||
|
with open("input") as f:
|
||
|
reindeers = [n.strip() for n in f.readlines()]
|
||
|
|
||
|
TIME_ELAPSED = 2503
|
||
|
|
||
|
max_distance = 0
|
||
|
|
||
|
for reindeer in reindeers:
|
||
|
name = reindeer.split(" ")[0]
|
||
|
[speed, fly_time, rest_time] = [int(x) for x in re.findall("[0-9]+", reindeer)]
|
||
|
|
||
|
cycle = fly_time + rest_time
|
||
|
count_cycles, rest = divmod(TIME_ELAPSED, cycle)
|
||
|
rest = min(rest, fly_time)
|
||
|
|
||
|
distance = count_cycles * fly_time * speed + rest * speed
|
||
|
|
||
|
print(
|
||
|
f"{name.ljust(8)}: {speed}km/s for {fly_time}s, rest {rest_time}s -> {distance}km"
|
||
|
)
|
||
|
|
||
|
if distance > max_distance:
|
||
|
max_distance = distance
|
||
|
|
||
|
print()
|
||
|
print(max_distance)
|