From d370c43087bfc95418d649e90d60d9bef39c377f Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 14 Dec 2021 08:09:44 +0000 Subject: [PATCH] Completed day 10, task 2 --- Day-10/day10-2.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Day-10/day10-2.py diff --git a/Day-10/day10-2.py b/Day-10/day10-2.py new file mode 100644 index 0000000..cd97d31 --- /dev/null +++ b/Day-10/day10-2.py @@ -0,0 +1,43 @@ +#!/usr/bin/python3 + +from statistics import median + +lineScores = [] + +closers = { + '(':')', + '{':'}', + '[':']', + '<':'>' +} + +points = { + ')':1, + ']':2, + '}':3, + '>':4 +} + +with open('/home/jake/Documents/AoC-2021/Day-10/input.txt') as inputFile: + for line in inputFile: + line = line.strip('\n') + expecting = [] + invalid = False + for char in line: + if(char in closers): + expecting.insert(0,closers[char]) + else: + if(expecting[0] != char): + invalid = True + break + else: + del expecting[0] + if(invalid): + continue + else: + totalScore = 0 + for e in expecting: + totalScore*=5 + totalScore+=points[e] + lineScores.append(totalScore) +print("The middle score is: " + str(median(lineScores))) \ No newline at end of file