advent_of_code/10/10.py

34 lines
953 B
Python
Raw Normal View History

2021-12-10 07:20:31 +01:00
#!/usr/bin/env python
# 2021 - Advent Of Code - 10
def parse_file(file):
with open(file) as f:
i = 0
for line in f.readlines():
chunks = []
for c in line.strip():
if c in close_sign.values(): # open signs
chunks.append(c)
if c in close_sign:
last_open = chunks.pop()
if close_sign[c] != last_open:
print(f'found corrupted chunk at line {i}: {line.strip()}')
count_score[c] += 1
close_sign = {')': '(', ']': '[', '}': '{', '>': '<'}
count_score = {')': 0, ']': 0, '}': 0, '>': 0}
score_table = {')': 3, ']': 57, '}': 1197, '>': 25137}
2021-12-10 07:20:31 +01:00
# parse_file('input_example.txt')
parse_file('input.txt')
# print_hmap(heightmap)
print(f'char score {count_score}')
score = 0
for sign in close_sign:
score += count_score[sign] * score_table[sign]
2021-12-10 07:20:31 +01:00
print(f'score: {score}')