53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
from collections import defaultdict
|
|
|
|
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(12, "test_input2_1"),
|
|
(7410, "input2")
|
|
],
|
|
[
|
|
('fgij', "test_input2_2"),
|
|
('cnjxoritzhvbosyewrmqhgkul', "input2")
|
|
]
|
|
]
|
|
|
|
def part1(self) -> Any:
|
|
twos, threes = 0, 0
|
|
for label in self.getInput():
|
|
count = defaultdict(int)
|
|
for x in label:
|
|
count[x] += 1
|
|
|
|
if 2 in count.values():
|
|
twos += 1
|
|
if 3 in count.values():
|
|
threes += 1
|
|
|
|
return twos * threes
|
|
|
|
def part2(self) -> Any:
|
|
for x, l1 in enumerate(self.getInput()):
|
|
for l2 in self.getInput()[x + 1:]:
|
|
miss = 0
|
|
miss_id = -1
|
|
for i, c in enumerate(l1):
|
|
if not c == l2[i]:
|
|
miss += 1
|
|
miss_id = i
|
|
|
|
if miss > 1:
|
|
break
|
|
|
|
if miss == 1:
|
|
return l1[:miss_id] + l1[miss_id + 1:]
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2018, 2)
|
|
day.run(verbose=True)
|