AdventOfCode/2020/day02.py

9 lines
520 B
Python
Raw Normal View History

2020-12-10 18:43:53 +10:30
import re
ex = re.compile(r'(\d+)-(\d+) (\w): (.*)')
2020-12-10 19:06:43 +10:30
f = lambda i,j,c,s: (int(i), int(j), c, s) # Wish I could sneak this into the listcomp but can't think of a fun way to do that at present :(
2020-12-10 18:43:53 +10:30
with open('input02', 'r') as file:
2020-12-10 19:06:43 +10:30
data = [f(*ex.match(line).groups()) for line in file.readlines()]
2020-12-10 18:43:53 +10:30
2020-12-10 19:06:43 +10:30
print(f'Part 1: {[(i<=s.count(c)<=j) for i,j,c,s in data].count(True)}')
print(f'Part 2: {[(s[i-1]==c)^(s[j-1]==c) for i,j,c,s in data].count(True)}') # This is fragile, beware inputs that may have indices out of range!