コード例 #1
0
        public override string Solve()
        {
            var directions = _parser.GetData().Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var q     = 0;
            var r     = 0;
            var start = new AxialHexCoordinate(0, 0);
            var max   = int.MinValue;

            foreach (var direction in directions)
            {
                switch (direction)
                {
                case "n": q++; break;

                case "nw": q++; r--; break;

                case "ne": r++; break;

                case "s": q--; break;

                case "sw": r--; break;

                case "se": q--; r++; break;
                }

                var distance = new AxialHexCoordinate(q, r).GetDistanceTo(start);
                if (distance > max)
                {
                    max = distance;
                }
            }

            return(max.ToString());
        }
コード例 #2
0
        public int GetDistanceTo(AxialHexCoordinate other)
        {
            var cubeCoordinates      = ToCubeHex();
            var otherCubeCoordinates = other.ToCubeHex();

            return(Math.Max(
                       Math.Max(
                           Math.Abs(cubeCoordinates.X - otherCubeCoordinates.X),
                           Math.Abs(cubeCoordinates.Y - otherCubeCoordinates.Y)),
                       Math.Abs(cubeCoordinates.Z - otherCubeCoordinates.Z)));
        }