<jupyter_start><jupyter_text>Day 09Let's get the data first.<jupyter_code>import aocd
data = aocd.get_data(day=9, year=2020)
preamble = 25

# data = """35\n20\n15\n25\n47\n40\n62\n55\n65\n95\n102\n117\n150\n182\n127\n219\n299\n277\n309\n576"""
# preamble = 5

data = [int(x) for x in data.splitlines()]
# data<jupyter_output><empty_output><jupyter_text>Part 1<jupyter_code>def isasum(target, values):
    for i in range(len(values) - 1):
        for j in range(i + 1, len(values)):
            #print(' - Trying:', values[i], values[j])
            if (values[i] + values[j]) == target:
                return True
    return False

for i in range(preamble, len(data)):
    # print(data[i], '-', data[i-preamble:i])
    if not isasum(data[i], data[i-preamble:i]):
        print(data[i])
        break<jupyter_output>90433990<jupyter_text>Part 2<jupyter_code>outlier = 90433990

def isasummulti(target, values, length):
    for i in range(len(values) - 1):
        # print(' - Trying:', values[i:i+length], '==', target)
        if (sum(values[i:i+length])) == target:
            return values[i:i+length]
    return False

for i in range(2, len(data)):
    # print(data[i], '-', data[i-preamble:i])
    if isasummulti(outlier, data, i):
        print(min(isasummulti(outlier, data, i)) + max(isasummulti(outlier, data, i)))
        break<jupyter_output>11691646
{'fraction_non_alphanumeric': 0.16813509544787078, 'fraction_numerical': 0.06607929515418502, 'mean_word_length': 3.513245033112583, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '411618', 'license': 'MIT', 'n_tokens_mistral': 611, 'n_tokens_neox': 545, 'n_words': 102, 'path': '2020/Day09.ipynb', 'repo_name': 'jamesturton/advent_of_code', 'size': '1362'}