Beispiel #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++);
                    }
                }
            }
        }
Beispiel #2
0
        public string Run(Aoc.Framework.Part part)
        {
            if (part == Aoc.Framework.Part.Part1)
            {
                byte[]   input = Aoc.Framework.Input.GetIntVector(this, ",").Select(i => (byte)i).ToArray();
                KnotHash hash  = new KnotHash(256, 1);
                hash.Compute(input, false);
                return(hash.GetSimpleHash().ToString());
            }

            if (part == Aoc.Framework.Part.Part2)
            {
                KnotHash hash = new KnotHash(256, 64);
                hash.Compute(Aoc.Framework.Input.GetString(this), true);
                return(hash.GetDenseHash());
            }

            return("");
        }