2017 Day 9 Part 2
This commit is contained in:
parent
63093277b0
commit
84403086cc
1 changed files with 9 additions and 8 deletions
|
|
@ -1,9 +1,7 @@
|
|||
def part1(text):
|
||||
return score(clean(text))
|
||||
|
||||
|
||||
def clean(text: str) -> str:
|
||||
def clean(text: str) -> tuple[str, int]:
|
||||
out = ""
|
||||
removed = 0
|
||||
|
||||
i = 0
|
||||
garbage = False
|
||||
while i < len(text):
|
||||
|
|
@ -15,7 +13,7 @@ def clean(text: str) -> str:
|
|||
if garbage and c == ">":
|
||||
garbage = False
|
||||
elif garbage:
|
||||
pass
|
||||
removed += 1
|
||||
elif c == "<":
|
||||
garbage = True
|
||||
else:
|
||||
|
|
@ -23,7 +21,7 @@ def clean(text: str) -> str:
|
|||
i += 1
|
||||
|
||||
assert not garbage, "All garbage must be closed"
|
||||
return out
|
||||
return out, removed
|
||||
|
||||
|
||||
def score(text: str) -> int:
|
||||
|
|
@ -43,4 +41,7 @@ def score(text: str) -> int:
|
|||
with open("input/day09.txt") as f:
|
||||
puzzle_input = f.read()
|
||||
|
||||
print(part1(puzzle_input))
|
||||
|
||||
groups, garbage = clean(puzzle_input)
|
||||
print(score(groups))
|
||||
print(garbage)
|
||||
|
|
|
|||
Loading…
Reference in a new issue