advent-of-code/2020/day1/day1.py

22 lines
569 B
Python
Raw Normal View History

2024-12-03 14:27:19 +00:00
#! /usr/bin/env python3
from itertools import product
def part1(inp):
inp = [int(x) for x in inp]
result_pairs = [x for x in list(product(inp, inp)) if sum(x) == 2020]
print(result_pairs)
print(result_pairs[0][0] * result_pairs[0][1])
def part2(inp):
inp = [int(x) for x in inp]
result_pairs = [x for x in list(product(inp, repeat=3)) if sum(x) == 2020]
print(result_pairs)
print(result_pairs[0][0] * result_pairs[0][1] * result_pairs[0][2])
if __name__ == "__main__":
with open("input.txt") as f:
part2(f.readlines())