Ejemplo n.º 1
0
        public int Solution(string input)
        {
            string[]          instructions  = instructionsRepository.GetInstructions(input);
            List <(int, int)> visitedBlocks = cityStreetGrid.CalculateVisitedBlocksAfterMove(instructions);

            (int x, int y)lastBlock;
            (lastBlock.x, lastBlock.y) = visitedBlocks[^ 1];
Ejemplo n.º 2
0
        public int Solution(string input)
        {
            string[]          instructions        = instructionsRepository.GetInstructions(input);
            List <(int, int)> visitedBlocks       = cityStreetGrid.CalculateVisitedBlocksAfterMove(instructions);
            List <(int, int)> allVisitedLocations = cityStreetGrid.CalculateAllVisitedLocations(visitedBlocks);

            (int x, int y)firstRepeatedLocation = (0, 0);
            List <(int, int)> uniqueLocations = new List <(int, int)>();

            foreach ((int x, int y)visitedLocation in allVisitedLocations)
            {
                if (uniqueLocations.Contains(visitedLocation))
                {
                    firstRepeatedLocation = visitedLocation;
                    break;
                }

                uniqueLocations.Add(visitedLocation);
            }

            int blocksAway = Math.Abs(firstRepeatedLocation.x) + Math.Abs(firstRepeatedLocation.y);

            return(blocksAway);
        }