diff --git a/day03/sol.py b/day03/sol.py index 32a8f61..df5351a 100644 --- a/day03/sol.py +++ b/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)