day1: add python part1
This commit is contained in:
parent
051321c4c8
commit
b4004fd75f
1 changed files with 15 additions and 0 deletions
15
2020/day1/day1.py
Executable file
15
2020/day1/day1.py
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
from typing import Iterable
|
||||
|
||||
def find2020(nums: Iterable[int]) -> int:
|
||||
candidates = set()
|
||||
for num in nums:
|
||||
opposite = 2020-num
|
||||
if num in candidates:
|
||||
return num * opposite
|
||||
candidates.add(opposite)
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open(sys.argv[1], 'r') as f:
|
||||
print(find2020(int(n) for n in f.readlines()))
|
Loading…
Reference in a new issue