Пример #1
0
 /// <summary>
 /// Populates the Grid 2D bool array based on the binary knot hash of the
 /// input value and the row number.
 /// </summary>
 /// <param name="input">The string to hash.</param>
 /// <param name="size">The size of the grid.</param>
 private void InitialiseGrid(string input, int size)
 {
     Grid = new bool[size, size];
     for (int row = 0; row < size; row++)
     {
         string binaryhash = new KnotHash(input + "-" + row, true, 64).AsBinaryHash();
         for (int col = 0; col < size; col++)
         {
             Grid[row, col] = binaryhash.ElementAt(col) == '1';
         }
     }
 }
Пример #2
0
        static void Main(string[] args)
        {
            string hash = "oundnydw-";

            Square.gridSize = 128;
            int sum          = 0;
            int numOfRegions = 0;

            Square.grid = new Square[Square.gridSize, Square.gridSize];

            for (int i = 0; i < Square.gridSize; i++)
            {
                string        newhash = KnotHash.CalculateKnotHash(hash + i);
                StringBuilder row     = new StringBuilder();

                foreach (char z in newhash)
                {
                    row.Append(hexCharToBin[char.ToLower(z)]);
                }

                for (int j = 0; j < Square.gridSize; j++)
                {
                    Square.grid[j, i]     = new Square(j, i);
                    Square.grid[j, i].Val = row[j] - '0';
                    sum += row[j] - '0';
                }
            }

            foreach (var square in Square.grid)
            {
                if (square.Visited == false && square.Val == 1)
                {
                    square.lookForRegions();
                    numOfRegions++;
                }
            }

            Console.WriteLine(sum);
            Console.WriteLine(numOfRegions);
        }