import numpy as np file = "inputs/day7.input" numbers = [int(x) for x in open(file, "rb").read().decode().split(",")] def dist(n): return 0.5 * (n ** 2 + n) min_fuel = 999999999 best_pos = 0 for pos in range(max(numbers) + 1): fuel = sum(dist(abs(numbers - np.array(pos)))) if fuel < min_fuel: min_fuel = fuel best_pos = pos print(best_pos)