Advent-of-Code/2021/7/main.py
David Vereb 9c1dcaeece Day 7
2021-12-07 15:51:22 -05:00

14 lines
318 B
Python

values = []
with open('data', 'r') as fp:
values = fp.readline().strip().split(',')
for i in range(0, len(values)):
values[i] = int(values[i])
values.sort()
index = int(len(values) / 2)
total = 0
for i in range(0, len(values)):
if(i != index):
total += abs(values[i] - values[index])
print(total)