Ejemplo n.º 1
0
        public void PuzzleExample_FindFirstInvalid()
        {
            const int preambleLength = 5;
            var       system         = new XmasSystem(PuzzleExample);

            system.FindFirstInvalid(preambleLength).Should().Be(127);
        }
Ejemplo n.º 2
0
        public void Puzzle1_FindFirstInvalid()
        {
            const int preambleLength = 25;
            var       system         = new XmasSystem(Input.Day09);

            system.FindFirstInvalid(preambleLength).Should().Be(138879426L);
        }
Ejemplo n.º 3
0
        public static void Part1(string[] input)
        {
            Helper.PrintChallengePart("Part 1");

            XmasSystem xmas   = new XmasSystem(input);
            long       result = xmas.FindInvalidData(25);

            Console.WriteLine("Invalid: " + result);
        }
Ejemplo n.º 4
0
        public static void Part2(string[] input)
        {
            Helper.PrintChallengePart("Part 2");

            XmasSystem xmas   = new XmasSystem(input);
            long       result = xmas.FindInvalidData(25);
            long       sum    = xmas.FindContiguousSet(result);

            Console.WriteLine("Contiguous Sum: " + sum);
        }
Ejemplo n.º 5
0
        public void Puzzle2_FundSumOfMinAndMaxOfSetThatAddsToInvalid()
        {
            const long firstInvalid = 138879426L;
            var        system       = new XmasSystem(Input.Day09);

            var set = system.FindSetThatAddsToInvalid(firstInvalid);

            var(min, max) = (set.Min(), set.Max());

            (min + max).Should().Be(23761694L);
        }
Ejemplo n.º 6
0
        public void Day9Part1()
        {
            // Arrange
            string[] input = Helper.ParseInput(@"Inputs\\Day9_example.txt");

            //Act
            XmasSystem xmas   = new XmasSystem(input);
            long       result = xmas.FindInvalidData(5);

            //Assert
            Assert.AreEqual(127, result);
        }
Ejemplo n.º 7
0
        public void Day9Part2()
        {
            // Arrange
            string[] input = Helper.ParseInput(@"Inputs\\Day9_example.txt");

            //Act
            XmasSystem xmas   = new XmasSystem(input);
            long       result = xmas.FindInvalidData(5);
            long       sum    = xmas.FindContiguousSet(result);

            //Assert
            Assert.AreEqual(62, sum);
        }
Ejemplo n.º 8
0
        public void PuzzleExample_FindSetThatAddsToInvalid()
        {
            var expectedSet = new List <long> {
                15, 25, 47, 40
            };
            var system = new XmasSystem(PuzzleExample);

            var actual = system.FindSetThatAddsToInvalid(127);

            actual.Should().BeEquivalentTo(expectedSet);

            var(min, max) = (actual.Min(), actual.Max());

            (min + max).Should().Be(62);
        }