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.
25 lines
643 B
25 lines
643 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:
|
|
currentfuel = currentfuel + abs(crab-i)
|
|
|
|
smallestFuel = min(smallestFuel, currentfuel)
|
|
|
|
print(smallestFuel)
|