generated from alvesvaren/AoC-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
13.py
28 lines (23 loc) · 720 Bytes
/
13.py
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
import aoc
from sympy.ntheory.modular import crt
arrival, schedule = aoc.get_input(13).splitlines()
busses = schedule.split(",")
arrival = int(arrival)
minimum_bus = ()
for bus in busses:
if bus == "x":
continue
bus = int(bus)
first_bus_after_arrival = max(range(bus, arrival+bus, bus))
if not minimum_bus or first_bus_after_arrival < minimum_bus[1]:
minimum_bus = (bus, first_bus_after_arrival)
# https://www.geeksforgeeks.org/python-sympy-crt-method/ heh
m = []
v = []
for i, bus in enumerate(busses):
if bus != "x":
bus = int(bus)
m.append(bus)
v.append(bus - i)
print("Part 1:", minimum_bus[0]*(minimum_bus[1]-arrival))
print("Part 2:", crt(m, v)[0])