aoc2021/d07/d07_2.py

6 lines
184 B
Python

L=list(map(int,__import__("sys").stdin.read().split(",")))
def cost(a,b):
n=abs(a-b)
return ((n+1)*n)//2
print(min(sum(cost(l,i) for l in L) for i in range(min(L), max(L)+1)))