Minor cleanup

master
E. Almqvist 4 years ago
parent 446932b98b
commit 8e6cf00fe7
  1. 60
      2020/13.py

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

Loading…
Cancel
Save