Last active
December 10, 2020 11:23
-
-
Save rtt/647a5dd8d5c52298f69426ff2bc893a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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