Exemple #1
0
        private static int GetNumberOfRegions(string input)
        {
            int [,] grid = new int [128, 128];
            int regionIndicator = 1;

            for (int i = 0; i < 128; i++)
            {
                string             key      = input + "-" + i.ToString();
                Utilities.KnotHash knotHash = new Utilities.KnotHash(input);
                string             hash     = knotHash.GenerateHash();
                string             binary   = HexToBinary(hash);
                for (int j = 0; j < 128; j++)
                {
                    grid [i, j] = binary [j] == '0' ? -1 : 0;
                }
            }
            for (int i = 0; i < 128; i++)
            {
                for (int j = 0; j < 128; j++)
                {
                    if (grid [i, j] == 0)
                    {
                        FloodFill(grid, i, j, 0, regionIndicator);
                        regionIndicator++;
                        continue;
                    }
                }
            }
            return(regionIndicator - 1);
        }
Exemple #2
0
        public void PartTwo()
        {
            Utilities.KnotHash knotHash = new Utilities.KnotHash(stringInput);
            string             hex      = knotHash.GenerateHash();

            Console.WriteLine(hex);
            System.Windows.Clipboard.SetText(hex);
        }
Exemple #3
0
        private static int GetUsedSquares(string input)
        {
            int used = 0;

            for (int i = 0; i < 128; i++)
            {
                string             key      = input + "-" + i.ToString();
                Utilities.KnotHash knotHash = new Utilities.KnotHash(input);
                string             hash     = knotHash.GenerateHash();
                string             binary   = HexToBinary(hash);
                used += binary.Count(x => x == '1');
            }
            return(used);
        }