Watch
1
0
Fork
You've already forked advent-of-code
0

2017 Day 9 Part 2

This commit is contained in:
Jeremy Kaplan 2026-07-30 22:09:35 -04:00
commit 84403086cc

View file

@ -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)