clean up day 3 slightly

main
magical 2022-12-02 21:31:41 -08:00
parent 5d959e5aad
commit 7aece65dcb
1 changed files with 10 additions and 8 deletions

View File

@ -1,13 +1,15 @@
import string import string
letters = string.ascii_lowercase + string.ascii_uppercase letters = string.ascii_lowercase + string.ascii_uppercase
rs = [] data = []
t = 0 t = 0
for line in open("input"): for line in open("input"):
n = len(line.strip()) data.append(line.strip())
n //= 2
for line in data:
n = len(line) // 2
a, b = line[:n], line[n:] a, b = line[:n], line[n:]
rs.append(set(line[:2*n]))
u = set(a) & set(b) u = set(a) & set(b)
assert len(u) == 1 assert len(u) == 1
x = list(u)[0] x = list(u)[0]
@ -17,10 +19,10 @@ for line in open("input"):
print(t) print(t)
t = 0 t = 0
for i in range(0, len(rs), 3): for i in range(0, len(data), 3):
a, b, c = rs[i:i+3] a, b, c = map(set, data[i:i+3])
#print(a & b & c)
u = a & b & c u = a & b & c
#print(u)
assert len(u) == 1 assert len(u) == 1
x = list(u)[0] x = list(u)[0]
t += 1 + letters.index(x) t += 1 + letters.index(x)