-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_13.py
More file actions
24 lines (18 loc) · 738 Bytes
/
day_13.py
File metadata and controls
24 lines (18 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#%% Part 1
with open("day_13_input.txt") as input_data:
earliest_arrival = int(input_data.readline().strip())
bus_ids = [int(x) for x in input_data.readline().split(",") if x != "x"]
wait_time, bus_id = sorted((bus_id - earliest_arrival % bus_id, bus_id) for bus_id in bus_ids)[0]
print(wait_time, bus_id, wait_time * bus_id)
#%% Part 2
with open("day_13_input.txt") as input_data:
input_data.readline()
bus_ids = [(offset, int(x)) for offset, x in enumerate(input_data.readline().split(",")) if x != "x"]
step_size = bus_ids.pop(0)[1]
position = step_size
while bus_ids:
offset, bus_id = bus_ids.pop(0)
while (position + offset) % bus_id != 0:
position += step_size
step_size *= bus_id
position