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