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)