--- /dev/null
+"""Decode stupid 7 segment displays"""
+
+s = 0
+with open("8_input.txt") as f:
+ for line in f:
+ mapping = {}
+
+ digits = [set(d) for d in line.split("|")[0].strip().split(" ")]
+ to_decode = [set(d) for d in line.split("|")[1].strip().split(" ")]
+ for digit_letters in digits:
+ if len(digit_letters) == 2:
+ mapping[1] = digit_letters
+ elif len(digit_letters) == 3:
+ mapping[7] = digit_letters
+ elif len(digit_letters) == 4:
+ mapping[4] = digit_letters
+ elif len(digit_letters) == 7:
+ mapping[8] = digit_letters
+
+ # Identify the 9, it's a strict superset of 4
+ for digit_letters in [d for d in digits if d not in mapping.values()]:
+ if mapping[4] < digit_letters:
+ mapping[9] = digit_letters
+
+ # Identify the 3, 1 is a subset of 3, which is a subset of 9
+ for digit_letters in [d for d in digits if d not in mapping.values()]:
+ if mapping[1] < digit_letters and digit_letters < mapping[9]:
+ mapping[3] = digit_letters
+
+ # Identify the 5, it is a strict subset of 9
+ for digit_letters in [d for d in digits if d not in mapping.values()]:
+ if mapping[9] > digit_letters:
+ mapping[5] = digit_letters
+
+ # Identify the 2, it's the last one with 5 segments
+ for digit_letters in [d for d in digits if d not in mapping.values()]:
+ if len(digit_letters) == 5:
+ mapping[2] = digit_letters
+
+ # Identify the 6, 5 is a strict subset of it
+ for digit_letters in [d for d in digits if d not in mapping.values()]:
+ if mapping[5] < digit_letters:
+ mapping[6] = digit_letters
+ else:
+ # Only 0 remains
+ mapping[0] = digit_letters
+
+ decoded_digits = []
+ for digit_to_decode in to_decode:
+ for k, v in mapping.items():
+ if v == digit_to_decode:
+ decoded_digits.append(str(k))
+
+ decoded_digits = int("".join(decoded_digits))
+ print(decoded_digits)
+ s += decoded_digits
+
+print(s)