<jupyter_start><jupyter_text>Part 1<jupyter_code>def count_easy_digits(fn):
    with open(fn) as data:
        n=0
        for line in data.readlines():
            output = line.split('|')[1].strip()
            n+=len([digit for digit in output.split() if len(digit) in [7,4,3,2]])
        return n
assert count_easy_digits('d8p1_test.txt')==26
print(f"The answer is {count_easy_digits('d8p1.txt')}")<jupyter_output>The answer is 440<jupyter_text>Part 2This is legitimately a puzzle.<jupyter_code>def solve_line(line):
    for entry in line:
        entry = set(''.join(sorted(entry)))
        if len(entry)==2:
            one = entry
        elif len(entry)==3:
            seven = entry
        elif len(entry)==4:
            four = entry
        elif len(entry)==7:
            eight = entry

    for entry in line:
        entry = set(''.join(sorted(entry)))
        if len(entry)==5:
            if entry & seven == seven:
                three = entry
            elif (eight - four) & entry == (eight - four):
                two = entry
            else:
                five = entry
        elif len(entry)==6:
            if entry & seven != seven:
                six = entry
            elif (eight - four) & entry == (eight - four):
                zero = entry
            else:
                nine = entry

    output = ''
    for entry in line[-4:]:
        entry = set(''.join(sorted(entry)))
        if entry==zero:
            output+='0'
        elif entry==one:
            output+='1'
        elif entry==two:
            output+='2'
        elif entry==three:
            output+='3'
        elif entry==four:
            output+='4'
        elif entry==five:
            output+='5'
        elif entry==six:
            output+='6'
        elif entry==seven:
            output+='7'
        elif entry==eight:
            output+='8'
        elif entry==nine:
            output+='9'
        else:
            print(f'Failure with {entry}')
    return int(output)
def solve_table(fn):
    total = 0
    with open(fn) as data:
        for line in data.readlines():
            line = line.split()
            line.pop(10)
            total+=solve_line(line)
    return total
assert solve_table('d8p1_test.txt')==61229
print(f'The answer is {solve_table("d8p1.txt")}')<jupyter_output>The answer is 1046281
{'fraction_non_alphanumeric': 0.13036020583190394, 'fraction_numerical': 0.022727272727272728, 'mean_word_length': 1.7002314814814814, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '324889', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 747, 'n_tokens_neox': 718, 'n_words': 176, 'path': 'Day 8 - Seven Segment Search.ipynb', 'repo_name': 'cmillion/advent_of_code_2021', 'size': '2332'}