advent-of-code/2020/day01_expense.py

25 lines
518 B
Python
Raw Normal View History

from itertools import combinations
from math import prod
2020-12-01 09:12:36 +01:00
def main():
lines = []
with open("inputs/day01") as f:
for line in f:
lines.append(int(line.strip()))
res = solve(lines, 2)
print("result is", res)
res = solve(lines, 3)
print("result is", res)
def solve(expense_report, fix_number):
for combination in combinations(expense_report, fix_number):
if sum(combination) == 2020:
return prod(combination)
2020-12-01 09:12:36 +01:00
2020-12-02 08:58:58 +01:00
if __name__ == "__main__":
2020-12-01 09:12:36 +01:00
main()