from itertools import combinations
import numpy as np
def sum_target(num_list: list, combs: int, target: int) -> int:
for t in combinations(num_list, combs):
if sum(t) == target:
return np.prod(t)
if __name__ == '__main__':
with open('day_01_input.txt', 'r') as f:
input_num_list = [int(x) for x in f.readlines()]
# Part 1
print(f'{sum_target(input_num_list, 2, 2020)=}')
# Part 2
print(f'{sum_target(input_num_list, 3, 2020)=}')
Probably not as efficient as others but seems readable.
Here's my Python solution:
Probably not as efficient as others but seems readable.