adventofcode/2021/7/crabs.py

13 lines
305 B
Python
Raw Permalink Normal View History

2022-12-01 21:02:00 +01:00
with open("input", "r") as input:
input = list(map(int, input.read().strip().split(",")))
fuel = []
for i in range(min(input), max(input)):
total_fuel = 0
for x in input:
total_fuel += abs(i - x)
fuel.append(total_fuel)
fuel.sort()
print(fuel[0])