25 lines
465 B
Python
25 lines
465 B
Python
#!/usr/bin/python
|
|
|
|
import sys
|
|
from collections import defaultdict
|
|
|
|
with open("input01.txt","r") as f:
|
|
data = [int(i) for i in f.readline().split(',')]
|
|
|
|
count = defaultdict(int)
|
|
for i in data:
|
|
count[i] += 1
|
|
|
|
pos_min = min([i for i in count.keys()])
|
|
pos_max = max([i for i in count.keys()])
|
|
|
|
results = []
|
|
|
|
for pos in range(pos_min, pos_max+1):
|
|
tmp = 0
|
|
for i in count.keys():
|
|
a=abs(pos-i)
|
|
tmp += a*(a+1)/2*count[i]
|
|
results.append(tmp)
|
|
print(min(results))
|