Exemplo n.º 1
0
        public (int regions, int usedSquares) Count(string key)
        {
            var hasher = new KnotHash();

            var usedSquares = 0;
            var regions     = 0;
            var cells       = new int[128, 128];

            for (int row = 0; row < 128; row++)
            {
                var hash   = hasher.CalculateHash($"{key}-{row}");
                var binary = HashToBinary(hash);

                for (int column = 0; column < 128; column++)
                {
                    cells[column, row] = (binary[column] == '1' ? 0 : -1);
                    if (binary[column] == '1')
                    {
                        usedSquares++;
                    }
                }
            }

            for (int row = 0; row < 128; row++)
            {
                for (int column = 0; column < 128; column++)
                {
                    if (cells[column, row] == 0)
                    {
                        regions++;
                        cells[column, row] = regions;

                        //Look Right
                        if (column < 127)
                        {
                            ClearIfSet(cells, column + 1, row, regions);
                        }

                        //Look Down
                        if (row < 127)
                        {
                            ClearIfSet(cells, column, row + 1, regions);
                        }
                    }
                }
            }

            return(usedSquares, regions);
        }
Exemplo n.º 2
0
        public string CalculateHash(string given)
        {
            var hasher = new KnotHash();

            return(hasher.CalculateHash(given));
        }