advent-of-code/2020/01/d1.py

16 lines
386 B
Python
Raw Normal View History

from itertools import combinations
2020-12-01 07:16:56 +01:00
with open('input') as f:
lines = list(map(int, f.readlines()))
2020-12-01 07:16:56 +01:00
def p1(lines):
a, b = filter(lambda t: t[0] + t[1] == 2020, combinations(lines, 2)).__next__()
return a * b
2020-12-01 07:16:56 +01:00
def p2(lines):
a, b, c = filter(lambda t: t[0] + t[1] + t[2] == 2020, combinations(lines, 3)).__next__()
return a * b * c
2020-12-01 07:16:56 +01:00
print(p1(lines))
print(p2(lines))