adventofcode2022/day03/sol.py

30 lines
514 B
Python
Raw Normal View History

2022-12-03 05:27:37 +00:00
import string
letters = string.ascii_lowercase + string.ascii_uppercase
rs = []
t = 0
for line in open("input"):
n = len(line.strip())
n //= 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]
#print(x)
t += 1 + letters.index(x)
print(t)
t = 0
for i in range(0, len(rs), 3):
a, b, c = rs[i:i+3]
#print(a & b & c)
u = a&b&c
assert len(u) == 1
x = list(u)[0]
t += 1 + letters.index(x)
print(t)