Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            PrintHeader("Day 14");

            var parallelQuery = Enumerable.Range(0, 128)
                                .AsParallel().AsOrdered()
                                .Select(i => $"{Input}-{i}")
                                .Select(s => Encoding.ASCII.GetBytes(s))
                                .Select(bs => KnotHashCalculator.Calculate(bs, KnotHashCalculator.MagicSuffix).CondenceKnotHash())
                                .ToList();

            var answer1 = parallelQuery
                          .Select(CalculateOnes)
                          .Sum();

            PrintAnswer("Problem 1 answer", answer1);

            var onesMap = parallelQuery
                          .Select(ConvertToZeroOnes)
                          .Select(enumerable => enumerable.ToArray())
                          .ToArray();

            var answer2 = CountIslands(onesMap);

            PrintAnswer("Problem 2 answer", answer2);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            PrintHeader("Day 10");

            var input = Input.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(byte.Parse).ToArray();
            var hash1 = KnotHashCalculator.Calculate(input, roundsCount: 1);

            PrintAnswer("Problem 1 answer", hash1[0] * hash1[1]);

            var inputBytes = Encoding.ASCII.GetBytes(Input);
            var hash2      = KnotHashCalculator.Calculate(inputBytes, KnotHashCalculator.MagicSuffix).CondenceKnotHash();
            var hashStr    = string.Join(string.Empty, hash2.Select(b => b.ToString("x2")));

            PrintAnswer("Problem 2 answer", hashStr);
        }