示例#1
0
        private void BuildMap()
        {
            // Create the hasher
            KnotHash hasher = new KnotHash();

            // Prepare the input
            string key = Aoc.Framework.Input.GetString(this);

            // Build the map of used cells
            int[,] grid = new int[128, 128];
            for (int i = 0; i < 128; ++i)
            {
                string row = key + "-" + i.ToString();
                hasher.Compute(row, true);
                byte[] hash = hasher.GetBytesHash();
                for (int j = 0; j < 128; j++)
                {
                    grid[i, j] = IsUsed(hash, j) ? 0 : -1;
                }
            }

            // Count bits
            _bits = 0;
            for (int i = 0; i < 128; ++i)
            {
                for (int j = 0; j < 128; j++)
                {
                    if (grid[i, j] >= 0)
                    {
                        _bits++;
                    }
                }
            }

            // Build groups
            _groupId = 1;
            for (int i = 0; i < 128; i++)
            {
                for (int j = 0; j < 128; j++)
                {
                    if (grid[i, j] == 0)
                    {
                        BuildGroup(grid, i, j, _groupId++);
                    }
                }
            }
        }