···11+import fileinput
22+from string import maketrans
33+from itertools import permutations
44+55+66+UNIQUES = {
77+ 1: 2,
88+ 4: 4,
99+ 7: 3,
1010+ 8: 7,
1111+}
1212+1313+DIGIT_MAP = {
1414+ 0: 'abcefg',
1515+ 1: 'cf',
1616+ 2: 'acdeg',
1717+ 3: 'acdfg',
1818+ 4: 'bcdf',
1919+ 5: 'abdfg',
2020+ 6: 'abdefg',
2121+ 7: 'acf',
2222+ 8: 'abcdefg',
2323+ 9: 'abcdfg',
2424+}
2525+2626+SEGMENTS_MAP = {v: str(k) for k, v in DIGIT_MAP.items()}
2727+2828+VALID_SEGMENTS = set(v for v in DIGIT_MAP.values())
2929+3030+ALL_SEGMENTS = 'abcdefg'
3131+3232+part_1 = 0
3333+part_2 = 0
3434+3535+for y, line in enumerate(fileinput.input()):
3636+ input, output = line.strip().split(' | ')
3737+3838+ # Solve part 1
3939+ for word in output.split():
4040+ if len(word) in UNIQUES.values():
4141+ part_1 += 1
4242+4343+ # Solve part 2
4444+ for perm in permutations('abcdefg', 7):
4545+ table = maketrans(ALL_SEGMENTS, perm)
4646+4747+ for word in input.split():
4848+ new_word = word.translate(table)
4949+ new_word = ''.join(sorted(new_word))
5050+5151+ if new_word not in VALID_SEGMENTS:
5252+ break
5353+ else:
5454+ ans = ''
5555+ for word in output.split():
5656+ new_word = word.translate(table)
5757+ new_word = ''.join(sorted(new_word))
5858+ ans += SEGMENTS_MAP[new_word]
5959+6060+ part_2 += int(ans)
6161+6262+6363+print "Part 1:", part_1
6464+print "Part 2:", part_2
6565+
+1-1
2021/starter.py
···2626board = {}
2727table = new_table(None, width=2, height=4)
28282929-# Uncomment for multi-group style inputs. :c
2929+# # Uncomment for multi-group style inputs. :c
3030# data = ''.join([line for line in fileinput.input()])
3131# groups = [g.split('\n') for g in data.split('\n\n')]
3232