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.
62 lines
1.3 KiB
62 lines
1.3 KiB
2 years ago
|
entries = open("input.txt", 'r').read().splitlines()
|
||
|
|
||
|
summa = 0
|
||
|
count = 0
|
||
|
for e in entries:
|
||
|
digits = e.split(" | ")[0].split()
|
||
|
output = e.split(" | ")[1].split()
|
||
|
dic = [set() for i in range(10)]
|
||
|
counts = {'a':0,'b':0,'c':0,'d':0,'e':0,'f':0,'g':0}
|
||
|
for s in digits:
|
||
|
if len(s) == 4:
|
||
|
dic[4].update(set(s))
|
||
|
elif len(s) == 2:
|
||
|
dic[1].update(set(s))
|
||
|
elif len(s) == 3:
|
||
|
dic[7].update(set(s))
|
||
|
elif len(s) == 7:
|
||
|
dic[8].update(set(s))
|
||
|
for l in s:
|
||
|
counts[l] += 1
|
||
|
for l in counts:
|
||
|
if counts[l] == 9:
|
||
|
for i in range(10):
|
||
|
if i not in [1,2,4,7,8]:
|
||
|
dic[i].add(l)
|
||
|
elif counts[l] == 6:
|
||
|
for i in range(10):
|
||
|
if i not in [1,2,3,4,7,8]:
|
||
|
dic[i].add(l)
|
||
|
elif counts[l] == 4:
|
||
|
for i in range(10):
|
||
|
if i not in [1,4,7,8,3,5,9]:
|
||
|
dic[i].add(l)
|
||
|
elif l in dic[7] and l not in dic[4]:
|
||
|
for i in range(10):
|
||
|
if i not in [1,4,7,8]:
|
||
|
dic[i].add(l)
|
||
|
elif counts[l] == 8:
|
||
|
for i in range(10):
|
||
|
if i not in [1,4,7,8,5,6]:
|
||
|
dic[i].add(l)
|
||
|
elif counts[l] == 7 and l in dic[4]:
|
||
|
for i in range(10):
|
||
|
if i not in [1,4,7,8,0]:
|
||
|
dic[i].add(l)
|
||
|
else:
|
||
|
for i in range(10):
|
||
|
if i not in [1,4,7,8,]:
|
||
|
dic[i].add(l)
|
||
|
|
||
|
for o in range(4):
|
||
|
for d in dic:
|
||
|
if set(output[o]) == d:
|
||
|
index = dic.index(d)
|
||
|
summa += index*10**(3-o)
|
||
|
if index in [1,4,7,8]:
|
||
|
count += 1
|
||
|
|
||
|
print(count)
|
||
|
print(summa)
|
||
|
|