day 7 short
This commit is contained in:
parent
c2321a1a72
commit
eec238335b
|
@ -1,6 +1,2 @@
|
|||
L=list(map(int,__import__("sys").stdin.read().split(",")))
|
||||
for i in range(min(L), max(L)+1):
|
||||
R=sum(abs(l-i) for l in L)
|
||||
print(R,i)
|
||||
# python3 d07_2.py < input | sort -n | head -1
|
||||
|
||||
print(min(sum(abs(l-i) for l in L) for i in range(min(L), max(L)+1)))
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
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
|
||||
return ((n+1)*n)//2
|
||||
print(min(sum(cost(l,i) for l in L) for i in range(min(L), max(L)+1)))
|
||||
|
|
Loading…
Reference in New Issue