parent
19a76fb3cb
commit
9df970d28b
1 changed files with 61 additions and 0 deletions
@ -0,0 +1,61 @@ |
||||
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) |
||||
|
Loading…
Reference in new issue