2021 day7/python: prettify

This commit is contained in:
Xiretza 2021-12-07 20:03:46 +01:00
parent e9a47c1863
commit 4ea70f38ea

View file

@ -3,13 +3,13 @@
import sys import sys
if __name__ == '__main__': if __name__ == '__main__':
inp = [int(i) for i in sys.stdin.readline().split(',')] positions = [int(i) for i in sys.stdin.readline().split(',')]
def calc(f): def calc(movement_cost):
return min([ return min(
sum(f(abs(crab-i)) for crab in inp) sum(movement_cost(abs(position-target)) for position in positions)
for i in range(min(inp), max(inp)+1) for target in range(min(positions), max(positions)+1)
]) )
print(calc(lambda n: n)) print(calc(lambda n: n))
print(calc(lambda n: n * (n+1)//2)) print(calc(lambda n: n * (n+1)//2))