--- /dev/null
+"""Find the least fuel for the sub-crabs"""
+with open("7_input.txt") as f:
+ crab_positions = [int(x) for x in f.read().split(",")]
+
+fuel_costs = []
+for target_position in range(max(crab_positions) + 1):
+ fuel_costs.append(0)
+ for crab_position in crab_positions:
+ fuel_costs[-1] += abs(target_position - crab_position)
+
+min_fuel = min(fuel_costs)
+min_fuel_position = fuel_costs.index(min_fuel)
+print(min_fuel_position, min_fuel)
--- /dev/null
+"""Find the least fuel for the sub-crabs with triangle fuel consumption"""
+with open("7_input.txt") as f:
+ crab_positions = [int(x) for x in f.read().split(",")]
+
+fuel_costs = []
+for target_position in range(max(crab_positions) + 1):
+ fuel_costs.append(0)
+ for crab_position in crab_positions:
+ delta = abs(target_position - crab_position)
+ fuel_costs[-1] += delta * (delta + 1)/2
+
+min_fuel = min(fuel_costs)
+min_fuel_position = fuel_costs.index(min_fuel)
+print(min_fuel_position, min_fuel)