My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add parse_line function to utils.py

+8 -1
+3 -1
2016/day04.py
··· 2 2 import fileinput 3 3 from collections import Counter 4 4 5 + from utils import parse_line 6 + 5 7 6 8 def decrypt(c, n): 7 9 if c == '-': ··· 14 16 north_pole_sector_id = None 15 17 16 18 for line in fileinput.input(): 17 - name, sector, checksum = re.match(r'(\S+)-(\d+)\[(\w{5})\]', line).groups() 19 + name, sector, checksum = parse_line(line, r'(\S+)-(\d+)\[(\w{5})\]') 18 20 sector = int(sector) 19 21 20 22 real_name = ''.join(decrypt(c, sector) for c in name)
+5
2016/utils.py
··· 1 + import re 1 2 import math 2 3 import operator 3 4 from functools import total_ordering ··· 6 7 LETTERS = [x for x in 'abcdefghijklmnopqrstuvwxyz'] 7 8 VOWELS = {'a', 'e', 'i', 'o', 'u'} 8 9 CONSONANTS = set(x for x in LETTERS if x not in VOWELS) 10 + 11 + 12 + def parse_line(line, regex): 13 + return re.match(regex, line).groups() 9 14 10 15 11 16 def mul(lst):