Aded 2017/09 part 1
This commit is contained in:
parent
532ca84519
commit
7a29670437
26
2017/09/9.md
26
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.
|
||||
- `<random characters>`, `17` characters.
|
||||
- `<<<<>`, `3` characters.
|
||||
- `<{!>}>`, `2` characters.
|
||||
- `<!!>`, `0` characters.
|
||||
- `<!!!>>`, `0` characters.
|
||||
- `<{o"i!a,<{i<a>`, `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).
|
||||
|
@ -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 #
|
||||
|
Loading…
Reference in New Issue
Block a user