This commit is contained in:
Stefan Harmuth 2022-11-20 11:20:51 +01:00
parent e3de15393a
commit cf13c83a63
2 changed files with 53 additions and 0 deletions

52
day09.py Normal file
View File

@ -0,0 +1,52 @@
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)

1
inputs/input9 Normal file

File diff suppressed because one or more lines are too long