parent
a1c971e81c
commit
7ced6f10a7
2 changed files with 71 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) |
||||||
|
|
@ -0,0 +1,10 @@ |
|||||||
|
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe |
||||||
|
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc |
||||||
|
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg |
||||||
|
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb |
||||||
|
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea |
||||||
|
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb |
||||||
|
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe |
||||||
|
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef |
||||||
|
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb |
||||||
|
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce |
Loading…
Reference in new issue