Пример #1
0
        static void Main(string[] args)
        {
            int searchNum = 312051;

            CreateSpiral(searchNum);

            var entryPoint  = new NumIndex();
            var searchPoint = new NumIndex();

            GetIndexes(searchNum, ref entryPoint, ref searchPoint);

            int rowSteps = entryPoint.rowIndex - searchPoint.rowIndex;

            if (rowSteps < 0)
            {
                rowSteps = Math.Abs(rowSteps);                  //turns negative to positive
            }
            int columnSteps = entryPoint.columnIndex - searchPoint.columnIndex;

            if (columnSteps < 0)
            {
                columnSteps = Math.Abs(columnSteps);
            }

            int sum = rowSteps + columnSteps;

            Console.WriteLine(sum);
            Console.ReadLine();
        }
Пример #2
0
        private static void GetIndexes(int searchNum, ref NumIndex entryPoint, ref NumIndex searchPoint)
        {
            for (int row = 0; row < _spiral.Count; row++)
            {
                for (int column = 0; column < _spiral[row].Count; column++)
                {
                    int num = _spiral[row][column];

                    if (num == 1)                       //Entrypoint
                    {
                        entryPoint.rowIndex    = row;
                        entryPoint.columnIndex = column;
                    }
                    if (num == searchNum)
                    {
                        searchPoint.rowIndex    = row;
                        searchPoint.columnIndex = column;
                    }
                }
            }
        }