Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- def main():
- with open("input.txt", 'r') as f:
- lines = f.readlines()
- nums25 = [int(i) for i in lines[:25]]
- new_lines = lines[25:]
- for i in new_lines:
- j = int(i)
- if not canAddTo(nums25, j):
- target = j
- print("Part 1:", target)
- break
- nums25 = nums25[1:]
- nums25.append(j)
- nums = collections.deque()
- subsum = 0
- for line in lines:
- i = int(line)
- if i >= target:
- nums = collections.deque()
- subsum = 0
- continue
- nums.append(i)
- subsum += i
- if len(nums) == 1:
- continue
- if subsum == target:
- return nums
- if subsum > target:
- while subsum > target and len(nums) <= 1:
- popped = nums.popleft()
- subsum -= popped
- if subsum == target:
- return nums
- def canAddTo(nums, target):
- for i in nums:
- if target-i in nums:
- return True
- return False
- if __name__ == "__main__":
- nums = main()
- print(nums)
- print(max(nums)+min(nums))
Advertisement
Add Comment
Please, Sign In to add comment