Advent-of-Code/2021/7/main.py

14 lines
318 B
Python
Raw Normal View History

2021-12-07 15:51:22 -05:00
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)