My Advent of Code solutions in Python.
kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code
python
1import fileinput
2from utils import chunks, parts
3
4INPUT = [line.strip() for line in fileinput.input()]
5
6# Part 1
7part_1 = 0
8for line in INPUT:
9 n = len(line)
10 fst, snd = parts(line, 2)
11
12 common = set(fst) & set(snd)
13
14 for c in common:
15 if c == c.lower():
16 part_1 += ord(c) - ord('a') + 1
17 else:
18 part_1 += ord(c) - ord('A') + 27
19
20print("Part 1:", part_1)
21
22# Part 2
23part_2 = 0
24for a, b, c in chunks(INPUT, 3):
25 common = set(a) & set(b) & set(c)
26
27 for c in common:
28 if c == c.lower():
29 part_2 += ord(c) - ord('a') + 1
30 else:
31 part_2 += ord(c) - ord('A') + 27
32
33print("Part 2:", part_2)