My Advent of Code solutions in Python.
kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code
python
1import os # NOQA
2import sys # NOQA
3import re # NOQA
4import math # NOQA
5import copy # NOQA
6import fileinput
7from string import ascii_uppercase, ascii_lowercase # NOQA
8from collections import Counter, defaultdict, deque, namedtuple # NOQA
9from itertools import count, product, permutations, combinations, combinations_with_replacement # NOQA
10
11from utils import parse_line, parse_nums, mul, all_unique, factors, memoize, primes # NOQA
12from utils import chunks, gcd, lcm, crt, print_grid, min_max_xy # NOQA
13from utils import new_table, transposed, rotated # NOQA
14from utils import md5, sha256, knot_hash # NOQA
15from utils import VOWELS, CONSONANTS # NOQA
16from utils import Point, DIRS, DIRS_4, DIRS_8 # NOQA # N (0, 1) -> E (1, 0) -> S (0, -1) -> W (-1, 0)
17
18# Itertools Functions:
19# product('ABCD', repeat=2) AA AB AC AD BA BB BC BD CA CB CC CD DA DB DC DD
20# permutations('ABCD', 2) AB AC AD BA BC BD CA CB CD DA DB DC
21# combinations('ABCD', 2) AB AC AD BC BD CD
22# combinations_with_replacement('ABCD', 2) AA AB AC AD BB BC BD CC CD DD
23
24tot = 0
25res = []
26board = {}
27table = new_table(None, width=2, height=4)
28
29timestamp = None
30buses = []
31
32# Uncomment for multi-group style inputs. :c
33# data = ''.join([line for line in fileinput.input()])
34# groups = [g.split('\n') for g in data.split('\n\n')]
35
36for y, line in enumerate(fileinput.input()):
37 line = line.strip()
38 nums = parse_nums(line)
39 data = parse_line(r'', line)
40
41 for x, c in enumerate(line):
42 board[Point(x, y)] = c
43
44 if y == 0:
45 timestamp = int(line)
46 else:
47 for x in line.split(','):
48 if x == 'x':
49 buses.append(None)
50 else:
51 buses.append(int(x))
52
53m = []
54x = []
55for i, b in enumerate(buses):
56 if b:
57 m.append(b)
58 x.append(i)
59
60print crt(x, m)
61
62
63
64num = 1777307553937916
65l1 = 2265213528143033
66
67num2 = num - l1
68
69print abs(num2) < abs(num)