This was easy. I do want to redo part 2 to be faster though because it currently takes 9 seconds to complete.
Part 1
with open("input.txt", "r") as f:
input = f.readlines()
times = input[0].split(":")[1].split()
distances = input[1].split(":")[1].split()
races = []
for i in range(len(times)):
races.append(dict(time=int(times[i]), distance=int(distances[i])))
total = 1
for race in races:
ways_to_win = 0
for ms in range(race["time"]):
if (ms * (race["time"] - ms)) > race["distance"]:
ways_to_win += 1
total *= ways_to_win
print(total)syntax highlighting by codehost
Part 2
with open("input.txt", "r") as f:
input = f.readlines()
time = int(input[0].split(":")[1].replace(" ", ""))
distance = int(input[1].split(":")[1].replace(" ", ""))
race = dict(time=time, distance=distance)
total = 1
ways_to_win = 0
for ms in range(race["time"]):
if (ms * (race["time"] - ms)) > race["distance"]:
ways_to_win += 1
total *= ways_to_win
print(total)syntax highlighting by codehost