advent-of-code/2020/solutions/1/python/main.py

18 lines
558 B
Python
Raw Permalink Normal View History

2020-12-02 12:07:57 +00:00
from typing import List
from itertools import product
from os.path import join, dirname
target = 2020
2020-12-04 18:45:03 +00:00
data = join(dirname(__file__), '../data.txt')
2020-12-02 12:07:57 +00:00
with open(data) as f:
numbers: List[int] = list(map(int, f.readlines()))
for a, b in product(numbers, numbers):
if a + b == target:
print(f'The numbers: {a} and {b}.\tSolution: {a*b}')
break
for a, b, c in product(numbers, numbers, numbers):
if a + b + c == target:
print(f'The numbers: {a}, {b} and {c}.\tSolution: {a*b*c}')
break