-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday6.py
More file actions
32 lines (24 loc) · 808 Bytes
/
day6.py
File metadata and controls
32 lines (24 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
file = open("input.txt")
lines = file.readlines()
def race_wins(time, dist):
wins = 0
for hold_time in range(time):
distance = (time - hold_time) * hold_time
if distance > dist:
wins += 1
return wins
def part1():
times = list(map(int, lines[0].split(":")[1].strip().split()))
distances = list(map(int, lines[1].split(":")[1].strip().split()))
races = [(times[i], distances[i]) for i in range(len(times))]
prod = 1
for time, dist in races:
prod *= race_wins(time, dist)
return prod
def part2():
time = int("".join(lines[0].split(":")[1].strip().split()))
distance = int("".join(lines[1].split(":")[1].strip().split()))
return race_wins(time, distance)
print("Part 1:", part1())
print("Part 2:", part2())
file.close()