Uglify 2020 day02
This commit is contained in:
parent
27395c908c
commit
de078fee90
|
@ -1,10 +1,8 @@
|
||||||
import re
|
import re
|
||||||
ex = re.compile(r'(\d+)-(\d+) (\w): (.*)')
|
ex = re.compile(r'(\d+)-(\d+) (\w): (.*)')
|
||||||
|
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 :(
|
||||||
with open('input02', 'r') as file:
|
with open('input02', 'r') as file:
|
||||||
data = [ex.match(line).groups() for line in file.readlines()]
|
data = [f(*ex.match(line).groups()) for line in file.readlines()]
|
||||||
|
|
||||||
valid = [(int(i)<=s.count(c)<=int(j)) for i,j,c,s in data]
|
print(f'Part 1: {[(i<=s.count(c)<=j) for i,j,c,s in data].count(True)}')
|
||||||
print(f'Part 1: {valid.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!
|
||||||
|
|
||||||
valid2 = [(s[int(i)-1]==c)^(s[int(j)-1]==c) for i,j,c,s in data] # This is fragile, beware inputs that may have indices out of range!
|
|
||||||
print(f'Part 2: {valid2.count(True)}')
|
|
||||||
|
|
Loading…
Reference in New Issue