clean up day 3 slightly
parent
5d959e5aad
commit
7aece65dcb
18
day03/sol.py
18
day03/sol.py
|
@ -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)
|
||||
u = 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)
|
||||
|
|
Loading…
Reference in New Issue