[Python/2018] Move solutions into .py files

This commit is contained in:
Felix Bargfeldt 2023-10-29 17:04:13 +01:00
parent edb04277c6
commit 40e767096e
Signed by: Defelo
GPG key ID: 2A05272471204DD3
60 changed files with 1518 additions and 3541 deletions

30
Python/2018/02.py Normal file
View file

@ -0,0 +1,30 @@
from lib import *
input = read_input(2018, 2)
def count(box, n):
return any(box.count(c) == n for c in set(box))
counter = {2: 0, 3: 0}
for line in input.splitlines():
counter[2] += count(line, 2)
counter[3] += count(line, 3)
print(counter[2] * counter[3])
def compare(a, b):
return len(a) == len(b) and sum(x != y for x, y in zip(a, b)) == 1
lines = input.splitlines()
for a in lines:
for b in lines:
if compare(a, b):
print("".join(x for x, y in zip(a, b) if x == y))
break
else:
continue
break