Exemple #1
0
        public static (int DistanceFromStart, int FurthestDistance) Solve(string input)
        {
            var path     = input.Split(',');
            var start    = new HexGridLocation();
            var location = new HexGridLocation();
            var furthestDistanceFromStart = 0;
            var currentDistance           = 0;

            foreach (var move in path)
            {
                if (move == "n")
                {
                    location.MoveNorth();
                }
                else if (move == "ne")
                {
                    location.MoveNorthEast();
                }
                else if (move == "nw")
                {
                    location.MoveNorthWest();
                }
                else if (move == "s")
                {
                    location.MoveSouth();
                }
                else if (move == "se")
                {
                    location.MoveSouthEast();
                }
                else if (move == "sw")
                {
                    location.MoveSouthWest();
                }

                currentDistance = location.DistanceFrom(start);
                if (currentDistance > furthestDistanceFromStart)
                {
                    furthestDistanceFromStart = currentDistance;
                }
            }

            return(currentDistance, furthestDistanceFromStart);
        }
Exemple #2
0
 public int DistanceFrom(HexGridLocation location)
 {
     return((Math.Abs(X - location.X) + Math.Abs(Y - location.Y) + Math.Abs(Z - location.Z)) / 2);
 }