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): def clean(text: str) -> tuple[str, int]:
return score(clean(text))
def clean(text: str) -> str:
out = "" out = ""
removed = 0
i = 0 i = 0
garbage = False garbage = False
while i < len(text): while i < len(text):
@ -15,7 +13,7 @@ def clean(text: str) -> str:
if garbage and c == ">": if garbage and c == ">":
garbage = False garbage = False
elif garbage: elif garbage:
pass removed += 1
elif c == "<": elif c == "<":
garbage = True garbage = True
else: else:
@ -23,7 +21,7 @@ def clean(text: str) -> str:
i += 1 i += 1
assert not garbage, "All garbage must be closed" assert not garbage, "All garbage must be closed"
return out return out, removed
def score(text: str) -> int: def score(text: str) -> int:
@ -43,4 +41,7 @@ def score(text: str) -> int:
with open("input/day09.txt") as f: with open("input/day09.txt") as f:
puzzle_input = f.read() puzzle_input = f.read()
print(part1(puzzle_input))
groups, garbage = clean(puzzle_input)
print(score(groups))
print(garbage)