aoc2021/d07/d07_2.py

9 lines
241 B
Python
Raw Normal View History

2021-12-08 01:26:52 +00:00
L=list(map(int,__import__("sys").stdin.read().split(",")))
def cost(a,b):
n=abs(a-b)
return ((n+1)*n)/2
for i in range(min(L), max(L)+1):
R=sum(cost(l,i) for l in L)
print(R,i)
# python3 d07_2.py < input | sort -n | head -1