A repro for all my Advent of ode tasks
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.
 

27 lines
709 B

import os
import sys
dir = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(dir, './input.txt'), 'r') as input_file:
lines = input_file.readlines()
line = lines[0].strip()
crabsString = line.split(',')
crabs = [int(numeric_string) for numeric_string in crabsString]
maxDistance = max(crabs)
minDistance = min(crabs)
smallestFuel = 9999999999999999999999
for i in range(minDistance, maxDistance+1):
currentfuel = 0
for crab in crabs:
steps = abs(crab-i)
a_sum = steps*((steps+1)/2)
currentfuel = currentfuel + a_sum
smallestFuel = min(smallestFuel, currentfuel)
print(smallestFuel)