24 lines
451 B
Python
24 lines
451 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():
|
||
|
tmp += abs(pos-i)*count[i]
|
||
|
results.append(tmp)
|
||
|
print(min(results))
|