Compare commits
No commits in common. "364261047dcfcfe4ebda7d796d09f979572444e9" and "2d47813106223752a05f55c6cb53580bd1abf85b" have entirely different histories.
364261047d
...
2d47813106
1 changed files with 0 additions and 22 deletions
22
day1/day1.py
22
day1/day1.py
|
@ -1,22 +0,0 @@
|
||||||
#!/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))
|
|
Loading…
Reference in a new issue