<jupyter_start><jupyter_text>Day 1<jupyter_code>import pandas as pd

df1 = pd.read_csv("input.txt", header=None)
arr=df1.values<jupyter_output><empty_output><jupyter_text>Part 1<jupyter_code>def getPairs(arr, sum):
    N = len(arr)
    l = 0
    r = N - 1

    # sort array
    arr = sorted(arr, key=(lambda xs: xs[0]))

    # invariant I: only elements in arr[l..r) can be part of the correct pair
    #              && l < r
    #
    # This means we only need to consider elements in arr[l..r).
    while (l < r):

        # I && l < r
        lr_sum = arr[l] + arr[r]

        if lr_sum < sum:
            # arr[l] cannot be part of the correct pair. Since arr is sorted,
            # any pair containing arr[l] will have even smaller sum. Hence, I
            # is maintained.
            l += 1

        elif lr_sum > sum:
            # arr[r] cannot be part of the correct pair. Since arr is sorted,
            # any pair containing arr[r] will have even larger sum. Hence, I
            # is maintained.
            r -= 1

        else:
            # found the correct pair, print and return
            print(arr[l], arr[r])
            return arr[l], arr[r]

    # I && l == r => no correct pair in arr[0..N)
    raise Exception("Could not find pair")

try:
    ans1, ans2 = getPairs(arr, 2020)
    print(ans1 * ans2)
except Exception as e:
    print(e)<jupyter_output>[896] [1124]
[1007104]<jupyter_text>Part 2Three entries<jupyter_code>import numpy as np

arr1=np.ndarray.flatten(arr)
arr1.sort()
arr1
def getTriplet(arr, sum): 
    n = len(arr)
    
    arr.sort() # sort from lowest to highest, fix first element
    
    for i in range(0, n-2): 
        l = i + 1 # left is one after locked value
          
        r = n-1 # right is end of array
        while (l < r): 
            if( arr[i] + arr[l] + arr[r] == sum): 
                print(arr[i], arr[l], arr[r])
                return arr[i], arr[l], arr[r]

            # if less than sum, move to a larger number (left move)
            elif (arr[i] + arr[l] + arr[r] < sum): 
                l += 1
            # if more than sum, move to a smaller number (right move)
            else: # A[i] + A[l] + A[r] > sum 
                r -= 1
  
    # rip no triplet shrugs
    return 0,0,0

ans1,ans2,ans3=getTriplet(arr1,2020)
print(ans1*ans2*ans3)<jupyter_output>24 539 1457
18847752
{'fraction_non_alphanumeric': 0.11827045358202629, 'fraction_numerical': 0.030945315811784654, 'mean_word_length': 1.935323383084577, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '182575', 'license': 'MIT', 'n_tokens_mistral': 868, 'n_tokens_neox': 802, 'n_words': 267, 'path': 'day1/AoC_day1.ipynb', 'repo_name': 'gnaprs/AoC-2020', 'size': '2359'}