Day 13, part 1

This commit is contained in:
Søren Rasmussen 2020-12-14 15:49:35 +01:00
parent c3975b22ae
commit 3b55df5ff5

23
2020/13/main.py Normal file
View file

@ -0,0 +1,23 @@
test = (
939,
"7,13,x,x,59,x,31,19",
)
data = (
1002462,
"37,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,601,x,x,x,x,x,x,x,x,x,x,x,19,x,x,x,x,17,x,x,x,x,x,23,x,x,x,x,x,29,x,443,x,x,x,x,x,x,x,x,x,x,x,x,13",
)
def part_1(departure, bus_ids):
buses = [int(x) for x in bus_ids.split(",") if x != "x"]
distances = [(departure // x + 1) * x - departure for x in buses]
idx = distances.index(min(distances))
return buses[idx], distances[idx]
id, wait = part_1(*test)
assert id*wait == 295
id, wait = part_1(*data)
print(f"1: Answer is {id*wait}")