advent/2018/02.py
Joseph Montanaro d6c1d10fca start 2018
2018-12-05 22:08:41 -08:00

30 lines
640 B
Python

from collections import Counter
from itertools import combinations
with open('data/02.txt') as f:
data = [r.strip() for r in f]
totals = {2: 0, 3: 0}
for item in data:
counter = Counter(item)
for n in 2, 3:
if n in counter.values():
totals[n] += 1
print(f'Part 1:\n{totals[2] * totals[3]}\n')
def compare(a, b):
different = 0
for charA, charB in zip(a, b):
if charA != charB:
different += 1
if different > 1:
return False
return True
for a, b in combinations(data, 2):
if compare(a, b):
print(''.join(c for c, d in zip(a, b) if c == d))