Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }