2020-12-01 16:40:10 +01:00
|
|
|
#!/usr/bin/env python
|
2020-12-01 16:50:45 +01:00
|
|
|
import itertools
|
2020-12-01 16:40:10 +01:00
|
|
|
import sys
|
|
|
|
from typing import Iterable
|
|
|
|
|
2020-12-01 16:50:45 +01:00
|
|
|
def product(nums: Iterable[int]) -> int:
|
|
|
|
"""
|
|
|
|
Returns the product of all elements in 'nums'
|
|
|
|
"""
|
|
|
|
x = 1
|
2020-12-01 16:40:10 +01:00
|
|
|
for num in nums:
|
2020-12-01 16:50:45 +01:00
|
|
|
x *= num
|
|
|
|
return x
|
|
|
|
|
|
|
|
def find_summing(arity: int, nums: Iterable[int]) -> int:
|
|
|
|
return product(next(filter(lambda xs: sum(xs) == 2020, itertools.permutations(nums, r=arity))))
|
2020-12-01 16:40:10 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-12-06 12:02:35 +01:00
|
|
|
nums = [int(n) for n in sys.stdin.readlines()]
|
2020-12-01 16:50:45 +01:00
|
|
|
print(find_summing(2, nums))
|
|
|
|
print(find_summing(3, nums))
|