|
|
@ -1,7 +1,6 @@ |
|
|
|
#!/usr/bin/env python |
|
|
|
#!/usr/bin/env python |
|
|
|
|
|
|
|
|
|
|
|
from aoc import get_input # AoC |
|
|
|
from aoc import get_input # AoC |
|
|
|
import re # regex |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = get_input(13).splitlines() |
|
|
|
data = get_input(13).splitlines() |
|
|
|
|
|
|
|
|
|
|
@ -11,43 +10,39 @@ busses = [] |
|
|
|
for busid in data[1].split(","): |
|
|
|
for busid in data[1].split(","): |
|
|
|
if(busid != "x"): |
|
|
|
if(busid != "x"): |
|
|
|
busses.append(int(busid)) |
|
|
|
busses.append(int(busid)) |
|
|
|
# else: |
|
|
|
|
|
|
|
# busses.append(busid) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##busses.sort() |
|
|
|
busses.sort() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getTimestamp(busid, i): |
|
|
|
def getTimestamp(busid, i): |
|
|
|
return busid * i |
|
|
|
return busid * i |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# bustimes = dict() |
|
|
|
bustimes = dict() |
|
|
|
|
|
|
|
|
|
|
|
# for busid in busses: |
|
|
|
for busid in busses: |
|
|
|
# print("checking ", busid) |
|
|
|
i = 0 |
|
|
|
# i = 0 |
|
|
|
bustimes[busid] = [] |
|
|
|
# bustimes[busid] = [] |
|
|
|
while True: |
|
|
|
# while True: |
|
|
|
timestamp = getTimestamp(busid, i) |
|
|
|
# timestamp = getTimestamp(busid, i) |
|
|
|
bustimes[busid].append(timestamp) |
|
|
|
# bustimes[busid].append(timestamp) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if(timestamp > time): |
|
|
|
if(timestamp > time): |
|
|
|
# break |
|
|
|
break |
|
|
|
# else: |
|
|
|
else: |
|
|
|
# i += 1 |
|
|
|
i += 1 |
|
|
|
# continue |
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
# waittimes = dict() |
|
|
|
|
|
|
|
# for busid, t in bustimes.items(): |
|
|
|
|
|
|
|
# high = max(t) |
|
|
|
|
|
|
|
# waittimes[busid] = high - time |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# bestbusid = min(waittimes, key=waittimes.get) |
|
|
|
waittimes = dict() |
|
|
|
|
|
|
|
for busid, t in bustimes.items(): |
|
|
|
|
|
|
|
high = max(t) |
|
|
|
|
|
|
|
waittimes[busid] = high - time |
|
|
|
|
|
|
|
|
|
|
|
# thing = bestbusid * waittimes[bestbusid] |
|
|
|
bestbusid = min(waittimes, key=waittimes.get) |
|
|
|
|
|
|
|
|
|
|
|
# print(bestbusid, thing) |
|
|
|
thing = bestbusid * waittimes[bestbusid] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Part 2 |
|
|
|
|
|
|
|
|
|
|
|
bus = dict() |
|
|
|
bus = dict() |
|
|
|
i = 0 |
|
|
|
i = 0 |
|
|
@ -57,19 +52,18 @@ for busid in data[1].split(","): |
|
|
|
|
|
|
|
|
|
|
|
i += 1 |
|
|
|
i += 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
minindex, maxindex = 0, len(bus) - 1 |
|
|
|
|
|
|
|
from sympy.ntheory.modular import crt |
|
|
|
from sympy.ntheory.modular import crt |
|
|
|
|
|
|
|
|
|
|
|
thing = [] |
|
|
|
pos = [] |
|
|
|
buss = [] |
|
|
|
buss = [] |
|
|
|
for i, busid in bus.items(): |
|
|
|
for i, busid in bus.items(): |
|
|
|
thing.append(i) |
|
|
|
pos.append(i) |
|
|
|
buss.append(busid) |
|
|
|
buss.append(busid) |
|
|
|
|
|
|
|
|
|
|
|
print(bus, buss, thing) |
|
|
|
hello = crt(buss, pos) |
|
|
|
hello = crt(buss, thing) |
|
|
|
|
|
|
|
print(hello) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thething = hello[1] - hello[0] |
|
|
|
thething = hello[1] - hello[0] |
|
|
|
print(thething) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Part1", thing) |
|
|
|
|
|
|
|
print("Part2", thething) |
|
|
|