Ejemplo n.º 1
0
        public int SolvePart1(int numberOfElements, string lengths)
        {
            var hasher = new KnotHash();

            var list         = hasher.BuildListOfNumbers(numberOfElements);
            var finalLengths = lengths.Split(',').Select(l => byte.Parse(l)).ToArray();

            hasher.DoSingleRound(finalLengths, list, currentPosition: 0, skipSize: 0);

            return(list[0] * list[1]);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public string CalculateHash(string given)
        {
            var hasher = new KnotHash();

            return(hasher.CalculateHash(given));
        }