Solved 2017/09 part 2

This commit is contained in:
FrederikBaerentsen 2024-11-22 22:09:02 +01:00
parent ef196af7e3
commit 4cc516a620
2 changed files with 15 additions and 10 deletions

View File

@ -72,8 +72,6 @@ group that immediately contains it. (The outermost group gets a score of
Your puzzle answer was `11898`.
The first half of this puzzle is complete! It provides one gold star: \*
## \-\-- Part Two \-\-- {#part2}
Now, you\'re ready to remove the garbage.
@ -93,7 +91,13 @@ nor do any canceled characters or the `!` doing the canceling.
*How many non-canceled characters are within the garbage* in your puzzle
input?
Answer:
Your puzzle answer was `5601`.
Although it hasn\'t changed, you can still [get your puzzle
Both parts of this puzzle are complete! They provide two gold stars:
\*\*
At this point, you should [return to your Advent calendar](/2017) and
try another puzzle.
If you still want to see it, you can [get your puzzle
input](9/input).

View File

@ -35,11 +35,12 @@ if part == 1:
if part == 2:
with open(input_f) as file:
for line in file:
print(line.rstrip(), end=' ')
#print(line.rstrip(), end=' ')
length = 0
clean_string = line.rstrip()
clean_string = re.sub(r"!.",'',clean_string)
print(clean_string)
clean_string = re.findall(r"<.*?>", clean_string)
for c in clean_string:
clean_string = c.replace('<','',1).replace('>','',1)
print(len(clean_string))
clean_string = re.findall(r"<(.*?)>", clean_string)
for i in clean_string:
length += len(i)
print(length)