Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2020 15:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
def getFirstNonSum(lookback, data):
for i in range(lookback, len(data)):
if not any(
[((data[i] - summand in data[i-lookback:i]) and \
(summand != data[i]/2))
for summand in data[i-lookback:i]] \
): return data[i]
def findListSumTo(target, data):
startNum = 0
length = 1
value = sum(data[startNum:startNum+length])
if value == target:
return data[startNum:startNum+length]
elif value > target:
startNum += 1
length = 1
length += 1
if __name__ == '__main__':
with open('input.txt', 'r') as infile:
data = [int(line) for line in infile]
invalidNum = getFirstNonSum(25, data)
print(f"Solution to part 1 is: {invalidNum}")
sumList = findListSumTo(invalidNum, data)
print(f"Solution to part 2 is: {max(sumList) + min(sumList)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment