def three(): for x in aoc_utils.input_int_list(): complements = main(2020 - x) if len(complements) <= 0: continue if x + complements[0] + complements[1] == 2020 and not ( complements[0] == x or complements[1] == x): return x * complements[0] * complements[1]
def main(target): array = [False] * target for x in aoc_utils.input_int_list(): if x < target: array[x] = True for i in range(target): if array[i] and array[target - i]: return i, (target - i) return []
#!/usr/bin/python3 from collections import * import itertools import random import re import sys import aoc_utils xs = [0] + sorted(aoc_utils.input_int_list()) di = {} for i, x in enumerate(xs): di[x] = [x + j for j in [1, 2, 3] if x + j in xs[i + 1 : i + 4]] e = max(di.keys()) cache = {} def paths(k): p = 0 if k >= e: return 1 for s in di[k]: if s not in cache: cache[s] = paths(s) p += cache[s] return p
#!/usr/bin/python3 import itertools import random import re import sys from collections import * import aoc_utils def main(xs: list[int]) -> int: print(sum(x < y for x, y in zip(xs, xs[3:]))) print(sum([1 for i, num in enumerate(xs[3:]) if num > xs[i]])) count = 0 for i in range(2, len(xs) - 1): if sum(xs[i - 1:i + 2]) > sum(xs[i - 2:i + 1]): count += 1 return count if __name__ == "__main__": print(main([199, 200, 208, 210, 200, 207, 240, 269, 260, 263])) print(main(aoc_utils.input_int_list()))
#!/usr/bin/python3 from collections import * import itertools import random import re import sys import aoc_utils """ My answers were Part A: 167829540 Part B: 28045630 """ inp = aoc_utils.input_int_list() preamble = 25 """ Finding all the sums of two numbers in the `preamble` length subarray Create a dictionary, in which keys are the sums of two numbers and the value is a tuple containing the indices of the two numbers that produced this sum. Although there are two nested for loops, it turns out as O(preamble * n), which is essentially O(n). """ di = {} for i in range(preamble, len(inp)): for j in range(i - preamble, i): di[inp[i] + inp[j]] = (i, j)