Let's see how far I get this year.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

day06-2.py 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from functools import reduce
  2. from helpers import Helper
  3. helper = Helper(debug=True)
  4. debug = helper.debug
  5. load_input = helper.load_input
  6. def main():
  7. lines = load_input(6)
  8. race = {}
  9. times = []
  10. distances = []
  11. for line in lines:
  12. header, values_str = line.split(":")
  13. for value in values_str.split():
  14. if header == "Time":
  15. times.append(value)
  16. else:
  17. distances.append(value)
  18. race["Time"] = int("".join(times))
  19. race["Distance"] = int("".join(distances))
  20. debug(race)
  21. win_ways = 0
  22. for held_time in range(race["Time"]):
  23. run_time = race["Time"] - held_time
  24. run_distance = run_time * held_time
  25. if run_distance > race["Distance"]:
  26. # 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.)")
  27. win_ways += 1
  28. print(f"Total ways to win the big race: {win_ways}")
  29. if __name__ == "__main__":
  30. main()