my advent of code 2021 solutions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.9 KiB

3 years ago
import sys
class line:
def __init__(self, tempinp, tempout):
self.inp = []
self.out = []
self.inp = tempinp.split(' ')
self.out = tempout.split(' ')
def decode(self):
self.one = []
self.ifone = False
self.four = []
self.iffour = False
self.seven = []
self.ifsev = False
self.eigth = []
self.numbers = self.inp + self.out
#print(self.numbers)
self.three = []
self.zero = []
self.nine = []
self.two = []
self.five = []
self.six = []
decoden = []
output = ''
for num in self.numbers:
if len(num) == 2:
self.ifone = True
self.one = sorted(num)
if len(num) == 4:
self.iffour = True
self.four = sorted(num)
if len(num) == 3:
self.ifseven = True
self.seven = sorted(num)
if len(num) == 7:
self.eigth = sorted(num)
if self.ifone and self.iffour:
for x in self.numbers:
tempnum = sorted(x)
if all(item in tempnum for item in self.one):
if len(x) == 5:
self.three = tempnum
if len(x) == 6:
if all(item in tempnum for item in self.four):
self.nine = tempnum
else:
self.zero = tempnum
elif len(x) == 6:
self.six = tempnum
else:
county = 0
for temp in self.four:
if temp in tempnum:
county += 1
if county == 2 and tempnum != self.one and tempnum != self.seven and tempnum != self.eigth:
self.two = tempnum
elif county == 3:
self.five = tempnum
decoden.append(self.zero)
decoden.append(self.one)
decoden.append(self.two)
decoden.append(self.three)
decoden.append(self.four)
decoden.append(self.five)
decoden.append(self.six)
decoden.append(self.seven)
decoden.append(self.eigth)
decoden.append(self.nine)
print(self.out)
print(decoden)
for number in self.out:
n = sorted(number)
for i in range(len(decoden)):
if decoden[i] == n:
output += str(i)
break
print(output)
return int(output)
terminal = []
count = 0
with open(sys.argv[1], 'r') as f:
for i in f.readlines():
tempin = i.strip()
inp, out = tempin.split(' | ')
terminal.append(line(inp, out))
for lin in terminal:
count += lin.decode()
print(count)