Ejemplo n.º 1
0
        public bool Solve(int part = 0)
        {
            string   input    = File.ReadAllText("Day10/input.txt");
            KnotHash knotHash = new KnotHash();

            if (part == 2)
            {
                int[] lengths = (input + "\x11\x1f\x49\x2f\x17").Select(c => (int)c).ToArray();

                for (int round = 0; round < 64; round++)
                {
                    knotHash.HashRound(lengths);
                }

                Console.WriteLine(knotHash.GetDenseHash());
            }
            else
            {
                int[] lengths = input.Split(',').Select(s => int.Parse(s)).ToArray();
                int   result  = knotHash.HashRound(lengths);
                Console.WriteLine(result);
            }

            return(true);
        }
Ejemplo n.º 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("");
        }