mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-12-21 23:56:30 +00:00
day 10
This commit is contained in:
parent
c493b24506
commit
a580157718
@ -8,7 +8,7 @@ A neat trick for part 2 is to simply reverse the order of the stack and count th
|
|||||||
<details>
|
<details>
|
||||||
<summary>Solutions</summary>
|
<summary>Solutions</summary>
|
||||||
<ol>
|
<ol>
|
||||||
<li>392097</li>
|
<li>288957</li>
|
||||||
<li>4263222782</li>
|
<li>4263222782</li>
|
||||||
</ol>
|
</ol>
|
||||||
</details>
|
</details>
|
||||||
|
@ -9,11 +9,6 @@ from os.path import dirname, join
|
|||||||
# Common
|
# Common
|
||||||
|
|
||||||
|
|
||||||
def log(str):
|
|
||||||
if False:
|
|
||||||
print(str)
|
|
||||||
|
|
||||||
|
|
||||||
def read_input(filename):
|
def read_input(filename):
|
||||||
data = join(dirname(__file__), '..', filename)
|
data = join(dirname(__file__), '..', filename)
|
||||||
with open(data) as f:
|
with open(data) as f:
|
||||||
@ -70,7 +65,6 @@ class NavigationSubsystemLineParser():
|
|||||||
"""
|
"""
|
||||||
Returns -1 for incomplete, 0 for valid, or the position of the first invalid character
|
Returns -1 for incomplete, 0 for valid, or the position of the first invalid character
|
||||||
"""
|
"""
|
||||||
log(f'Validating {self.line}')
|
|
||||||
while self.position < len(self.line):
|
while self.position < len(self.line):
|
||||||
expected = self._allowed_chars()
|
expected = self._allowed_chars()
|
||||||
char = self.line[self.position]
|
char = self.line[self.position]
|
||||||
@ -80,7 +74,6 @@ class NavigationSubsystemLineParser():
|
|||||||
else:
|
else:
|
||||||
expected = self.pairs[self.stack[-1]]
|
expected = self.pairs[self.stack[-1]]
|
||||||
if char != expected:
|
if char != expected:
|
||||||
log(f'Invalid char {char} at position {self.position}. Expected {expected}')
|
|
||||||
return ParseResult(ResultType.Corrupted, expected=expected, found=char)
|
return ParseResult(ResultType.Corrupted, expected=expected, found=char)
|
||||||
else:
|
else:
|
||||||
self.stack.pop()
|
self.stack.pop()
|
||||||
@ -100,8 +93,6 @@ class NavigationSubsystem():
|
|||||||
|
|
||||||
def count_corrupted(self) -> int:
|
def count_corrupted(self) -> int:
|
||||||
results = self.validate()
|
results = self.validate()
|
||||||
for result in results:
|
|
||||||
log(result)
|
|
||||||
points_map = {
|
points_map = {
|
||||||
')': 3,
|
')': 3,
|
||||||
']': 57,
|
']': 57,
|
||||||
@ -134,7 +125,6 @@ class NavigationSubsystem():
|
|||||||
if result.type == ResultType.Incomplete
|
if result.type == ResultType.Incomplete
|
||||||
]
|
]
|
||||||
points.sort()
|
points.sort()
|
||||||
log(points)
|
|
||||||
return points[len(points)//2]
|
return points[len(points)//2]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user