12345678910111213141516171819202122232425262728293031323334353637383940 |
- from functools import reduce
-
- from helpers import Helper
-
- helper = Helper(debug=True)
- debug = helper.debug
- load_input = helper.load_input
-
- def main():
- lines = load_input(6)
-
- race = {}
-
- times = []
- distances = []
- for line in lines:
- header, values_str = line.split(":")
- for value in values_str.split():
- if header == "Time":
- times.append(value)
- else:
- distances.append(value)
-
- race["Time"] = int("".join(times))
- race["Distance"] = int("".join(distances))
-
- debug(race)
-
- win_ways = 0
- for held_time in range(race["Time"]):
- run_time = race["Time"] - held_time
- run_distance = run_time * held_time
- if run_distance > race["Distance"]:
- # debug(f"I can win the race with time {held_time}ms (it'll run {run_time}ms at {held_time}mm/ms for {run_distance}mm total.)")
- win_ways += 1
-
- print(f"Total ways to win the big race: {win_ways}")
-
- if __name__ == "__main__":
- main()
|