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