From 8e6cf00fe7ca5b263a8b3dcfd8745909f38e441f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sun, 13 Dec 2020 08:21:25 +0100 Subject: [PATCH] Minor cleanup --- 2020/13.py | 60 ++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/2020/13.py b/2020/13.py index 4607a4f..6778f1f 100755 --- a/2020/13.py +++ b/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)