2020-12-01 09:41:23 +01:00
|
|
|
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()))
|
|
|
|
|
2020-12-01 09:41:23 +01:00
|
|
|
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()
|