Compare commits

...

2 commits

Author SHA1 Message Date
364261047d
day1: modify python for part2 2020-12-01 16:50:45 +01:00
2a315e81e1
day1: add python part1 2020-12-01 16:40:10 +01:00

22
day1/day1.py Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env python
import itertools
import sys
from typing import Iterable
def product(nums: Iterable[int]) -> int:
"""
Returns the product of all elements in 'nums'
"""
x = 1
for num in nums:
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))))
if __name__ == '__main__':
with open(sys.argv[1], 'r') as f:
nums = [int(n) for n in f.readlines()]
print(find_summing(2, nums))
print(find_summing(3, nums))