<jupyter_start><jupyter_text>Day 09 part A<jupyter_code>import numpy as np
infile="09a_input.txt"
with open(infile) as f:
    text=f.read()
vals=text.replace("\n"," ")
vals=np.fromstring(vals,dtype="int",sep=" ")
print("First 40 values:",vals[:40])
len(vals)
# check for each value if it is the sum of 2 of the previous 25
for idx in range(26,len(vals)):
    subset=vals[idx-25:idx] # previous 25 values
    sums=subset.reshape(1,-1)+subset.reshape(-1,1) # all possible sums as matrix (25x25)
    np.fill_diagonal(sums,-1) # exclude the diagonal as hit by setting the vals to -1
    is_valid=np.any(sums==vals[idx])
    
    if not is_valid:
        print(idx, vals[idx])
        break<jupyter_output>610 530627549<jupyter_text>part B<jupyter_code>target=530627549
# try all possible sums
success=False
for idx in range(len(vals)):
    summed=vals[idx]
    for idx2 in range(idx+1,len(vals)):
        summed+=vals[idx2]
        if summed>target:
            break # try next start value
        if summed==target:
            success=True
            break
    if success:
        print("Found values: start & end index:",idx,idx2)
        break
            

#final result
sub=vals[idx:idx2+1]
np.min(sub)+np.max(sub)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12900641025641027, 'fraction_numerical': 0.04326923076923077, 'mean_word_length': 3.460714285714286, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, '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': '350106', 'license': 'MIT', 'n_tokens_mistral': 475, 'n_tokens_neox': 441, 'n_words': 108, 'path': 'advent_of_code_09.ipynb', 'repo_name': 'walkernoreen/adventofcode2020', 'size': '1248'}