2021 day7/python: add solution

This commit is contained in:
Xiretza 2021-12-07 06:24:59 +01:00
parent eb8110c355
commit e9a47c1863

15
2021/day7/day7.py Executable file
View 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))