AdventOfCode/2020/day01.py

19 lines
418 B
Python
Raw Normal View History

2020-12-10 18:43:53 +10:30
with open('input01', 'r') as file:
data = sorted([int(i) for i in file.readlines()])
def find_pair_sum(total, data):
for x in data:
y = total - x
if y in data:
return x, y
return None, None
x, y = find_pair_sum(2020, data)
print(f'Part 1: {x}*{y} = {x*y}')
for idx, x in enumerate(data):
y, z = find_pair_sum(2020-x, data[idx+1:])
if y:
print(f'Part 2: {x}*{y}*{z} = {x*y*z}')
break