public int FindFuelToAlignMoreFuel() { int minFuel = int.MaxValue; for (int iCrab = MinCrab; iCrab <= MaxCrab; iCrab++) { int fuel = Crabs.Sum(c => (Math.Abs(c - iCrab) + 1) * Math.Abs(c - iCrab) / 2); if (fuel < minFuel) { minFuel = fuel; } } return(minFuel); }
public int FindFuelToAlign() { int minFuel = int.MaxValue; for (int iCrab = MinCrab; iCrab <= MaxCrab; iCrab++) { int fuel = Crabs.Sum(c => c < iCrab ? iCrab - c : c - iCrab); if (fuel < minFuel) { minFuel = fuel; } } return(minFuel); }