Skip to content

Instantly share code, notes, and snippets.

@rtt
Last active December 10, 2020 11:23
Show Gist options
  • Save rtt/647a5dd8d5c52298f69426ff2bc893a9 to your computer and use it in GitHub Desktop.
Save rtt/647a5dd8d5c52298f69426ff2bc893a9 to your computer and use it in GitHub Desktop.
from itertools import combinations
def get_input():
with open('./input9.txt') as inp:
return inp.read().strip().split('\n')
def part1():
inp = get_input()
pre = 25
n = 2
c = 25
d = []
for cursor, _ in enumerate(inp, start=c):
if not any(sum(x) == int(inp[cursor]) for x in combinations(map(int, inp[cursor-pre:cursor]), n)):
return int(inp[cursor])
def part2(p1):
inp = list(map(int, get_input()))
n = len(inp)
results = next(x for x in (next(inp[i:j] for j in range(i + 1, n) if sum(inp[i:j]) >= p1) for i in range(n)) if sum(x) == p1)
return sum([min(results), max(results)])
if __name__ == "__main__":
p1 = part1()
print(p1)
print(part2(p1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment