53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(10820, "input9")
|
|
],
|
|
[
|
|
(5547, "input9")
|
|
]
|
|
]
|
|
|
|
def parse_input(self) -> (int, int):
|
|
score = 0
|
|
garbage_count = 0
|
|
group_value = 1
|
|
is_garbage = False
|
|
ignore_next = False
|
|
for c in self.getInput():
|
|
if ignore_next:
|
|
ignore_next = False
|
|
elif not is_garbage and c == "<":
|
|
is_garbage = True
|
|
elif is_garbage and c == ">":
|
|
is_garbage = False
|
|
elif c == "!":
|
|
ignore_next = True
|
|
elif is_garbage:
|
|
garbage_count += 1
|
|
continue
|
|
elif c == "{":
|
|
score += group_value
|
|
group_value += 1
|
|
elif c == "}":
|
|
group_value -= 1
|
|
|
|
return score, garbage_count
|
|
|
|
def part1(self) -> Any:
|
|
s, _ = self.parse_input()
|
|
return s
|
|
|
|
def part2(self) -> Any:
|
|
_, c = self.parse_input()
|
|
return c
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2017, 9)
|
|
day.run(verbose=True)
|