adventofcode2022/day03/sol.py

32 lines
530 B
Python
Raw Normal View History

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