|
|
@@ -0,0 +1,83 @@ |
|
|
|
def count_segs(disp): |
|
|
|
d_set = set(disp) |
|
|
|
tot, t_segs = 0, len(d_set) |
|
|
|
for ltr in d_set: |
|
|
|
tot += disp.count(ltr) |
|
|
|
return tot, t_segs |
|
|
|
|
|
|
|
true_digits = { |
|
|
|
"aaaabbcceeffgggg": |
|
|
|
{ |
|
|
|
"len": count_segs("aaaabbcceeffgggg")[0], |
|
|
|
"segs": count_segs("aaaabbcceeffgggg")[1], |
|
|
|
"val": 0 |
|
|
|
}, |
|
|
|
"ccff": |
|
|
|
{ |
|
|
|
"len": count_segs("ccff")[0], |
|
|
|
"segs": count_segs("ccff")[1], |
|
|
|
"val": 1 |
|
|
|
}, |
|
|
|
"aaaaccddddeegggg": |
|
|
|
{ |
|
|
|
"len": count_segs("aaaaccddddeegggg")[0], |
|
|
|
"segs": count_segs("aaaaccddddeegggg")[1], |
|
|
|
"val": 2 |
|
|
|
}, |
|
|
|
"aaaaccddddffgggg": |
|
|
|
{ |
|
|
|
"len": count_segs("aaaaccddddffgggg")[0], |
|
|
|
"segs": count_segs("aaaaccddddffgggg")[1], |
|
|
|
"val": 3 |
|
|
|
}, |
|
|
|
"bbccddddff": |
|
|
|
{ |
|
|
|
"len": count_segs("bbccddddff")[0], |
|
|
|
"segs": count_segs("bbccddddff")[1], |
|
|
|
"val": 4 |
|
|
|
}, |
|
|
|
"aaaabbddddffgggg": |
|
|
|
{ |
|
|
|
"len": count_segs("aaaabbddddffgggg")[0], |
|
|
|
"segs": count_segs("aaaabbddddffgggg")[1], |
|
|
|
"val": 5 |
|
|
|
}, |
|
|
|
"aaaabbddddeeffgggg": |
|
|
|
{ |
|
|
|
"len": count_segs("aaaabbddddeeffgggg")[0], |
|
|
|
"segs": count_segs("aaaabbddddeeffgggg")[1], |
|
|
|
"val": 6 |
|
|
|
}, |
|
|
|
"aaaaccff": |
|
|
|
{ |
|
|
|
"len": count_segs("aaaaccff")[0], |
|
|
|
"segs": count_segs("aaaaccff")[1], |
|
|
|
"val": 7 |
|
|
|
}, |
|
|
|
"aaaabbccddddeeffgggg": |
|
|
|
{ |
|
|
|
"len": count_segs("aaaabbccddddeeffgggg")[0], |
|
|
|
"segs": count_segs("aaaabbccddddeeffgggg")[1], |
|
|
|
"val": 8 |
|
|
|
}, |
|
|
|
"aaaabbccddddffgggg": |
|
|
|
{ |
|
|
|
"len": count_segs("aaaabbccddddffgggg")[0], |
|
|
|
"segs": count_segs("aaaabbccddddffgggg")[1], |
|
|
|
"val": 9 |
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
def main(): |
|
|
|
with open("aoc8-1.txt","r") as file: |
|
|
|
lines = [line.split("|") for line in file.readlines()] |
|
|
|
lines = [line[1].strip() for line in lines] |
|
|
|
digits = [line.split(" ") for line in lines] |
|
|
|
false_digits = [count_segs(el)[1] for line in digits for el in line] |
|
|
|
looking_for = [2, 4, 3, 7] |
|
|
|
counter = len([digit for digit in false_digits if digit in looking_for]) |
|
|
|
print(counter) |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
main() |