You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
376 B
21 lines
376 B
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)
|