From 7a2967043764f735f01984529292d27372623bc1 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Fri, 22 Nov 2024 21:40:18 +0100 Subject: [PATCH] Aded 2017/09 part 1 --- 2017/09/9.md | 26 +++++++++++++++++++++++++- 2017/09/solution.py | 41 ++++++++++++----------------------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/2017/09/9.md b/2017/09/9.md index b6d50dd..c8f3b1c 100644 --- a/2017/09/9.md +++ b/2017/09/9.md @@ -70,6 +70,30 @@ group that immediately contains it. (The outermost group gets a score of *What is the total score* for all groups in your input? -To begin, [get your puzzle input](9/input). +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. + +To prove you\'ve removed it, you need to count all of the characters +within the garbage. The leading and trailing `<` and `>` don\'t count, +nor do any canceled characters or the `!` doing the canceling. + +- `<>`, `0` characters. +- ``, `17` characters. +- `<<<<>`, `3` characters. +- `<{!>}>`, `2` characters. +- ``, `0` characters. +- `>`, `0` characters. +- `<{o"i!a,<{i`, `10` characters. + +*How many non-canceled characters are within the garbage* in your puzzle +input? Answer: + +Although it hasn\'t changed, you can still [get your puzzle +input](9/input). diff --git a/2017/09/solution.py b/2017/09/solution.py index fc24504..b21fec0 100644 --- a/2017/09/solution.py +++ b/2017/09/solution.py @@ -2,48 +2,31 @@ import sys,re from pprint import pprint -input_f = 'test' +input_f = 'input' -part = 1 +part = -1 ######################################### # # # Part 1 # # # ######################################### - if part == 1: - with open(input_f) as file: + with open(input_f) as file: for line in file: - print(line.rstrip()) clean_string = re.sub(r"!.", "", line.rstrip()) clean_string = re.sub(r"<.*?>", "", clean_string) clean_string = re.sub(r",", "", clean_string) - #print(clean_string) + level = 0 + numbers = [] + for i in clean_string: + if i == '{': + level += 1 + if i == '}': + numbers.append(level) + level -= 1 - count = 1 - score = 0 - iteration = 0 - #print('Score of ',end='') - while True: - #print('Iteration: ', iteration) - matches = re.findall(r"\{\}", clean_string) - if not matches: - #print(increment,end='') - print('=',score) - break - - - - clean_string = re.sub(r"\{\}", "", clean_string) - iteration += 1 - for x in range(0,len(matches)): - score += iteration - print(iteration,end="") - + print(sum(numbers)) - #print(clean_string) - #rint(count) - input() ######################################### # # # Part 2 #