2021 day7/python: add solution
This commit is contained in:
parent
eb8110c355
commit
e9a47c1863
1 changed files with 15 additions and 0 deletions
15
2021/day7/day7.py
Executable file
15
2021/day7/day7.py
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
inp = [int(i) for i in sys.stdin.readline().split(',')]
|
||||
|
||||
def calc(f):
|
||||
return min([
|
||||
sum(f(abs(crab-i)) for crab in inp)
|
||||
for i in range(min(inp), max(inp)+1)
|
||||
])
|
||||
|
||||
print(calc(lambda n: n))
|
||||
print(calc(lambda n: n * (n+1)//2))
|
Loading…
Reference in a new issue