Exemplo n.º 1
0
        public async Task Day10_Part1_Test()
        {
            var asteroidMap = ".#..#\n.....\n#####\n....#\n...##";

            asteroidMap = @"......#.#.
#..#.#....
..#######.
.#.#.###..
.#..#.....
..#....#.#
#..#....#.
.##.#..###
##...#..#.
.#....####";
            asteroidMap = @"#.#...#.#.
.###....#.
.#....#...
##.#.#.#.#
....#.#.#.
.##..###.#
..#...##..
..##....##
......#...
.####.###.";
            asteroidMap = @".#..##.###...#######
##.############..##.
.#.######.########.#
.###.#######.####.#.
#####.##.#.##.###.##
..#####..#.#########
####################
#.####....###.#.#.##
##.#################
#####.##.###..####..
..######..##.#######
####.##.####...##..#
.#####..#.######.###
##...#.##########...
#.##########.#######
.####.#.###.###.#.##
....##.##.###..#####
.#.#.###########.###
#.#.#.#####.####.###
###.##.####.##.#..##";

            // Here is the real input. Those before are examples from the puzzle.
            var result = await fixture.Client.GetAsync("/2019/day/10/input");

            result.EnsureSuccessStatusCode();
            asteroidMap = await result.Content.ReadAsStringAsync();

            var mapArray           = asteroidMap.Split("\n").SkipLast(1).ToArray();
            var maxAsteroidsInView = Day10.CalculateMaxAsteroidsInView(mapArray);

            Assert.Equal(269, maxAsteroidsInView);
        }
Exemplo n.º 2
0
 public void SubArrayTest()
 {
     int[] array = new int[] { 1, 2, 3, 4, 5 };
     Day10.SubArray(array, 0).Should().BeEquivalentTo(new int[] { 1, 2, 3, 4, 5 });
     Day10.SubArray(array, 1).Should().BeEquivalentTo(new int[] { 2, 3, 4, 5 });
     Day10.SubArray(array, 2).Should().BeEquivalentTo(new int[] { 3, 4, 5 });
     Day10.SubArray(array, 3).Should().BeEquivalentTo(new int[] { 4, 5 });
     Day10.SubArray(array, 4).Should().BeEquivalentTo(new int[] { 5 });
     Day10.SubArray(array, 5).Should().BeEquivalentTo(new int[] { });
 }
Exemplo n.º 3
0
    public override string?CalculateSolution()
    {
        bool[,] disk = Enumerable.Range(0, 128)
                       .Select(i => _key + '-' + i)
                       .Select(s => Day10.GetKnotHash(s))
                       .Select(h => h.SelectMany(c => c.ToHexBits()))
                       .To2DArray(128, 128);

        return(Solution = disk.Cast <bool>().Count(b => b).ToString());
    }
Exemplo n.º 4
0
        public void TestSample1()
        {
            string sample1 = $".#..#\r.....\r#####\r....#\r...##";

            var asteroids = Day10Utils.ParseInput(sample1);
            var result    = Day10.GetNumberOfVisibleAsteroids(asteroids, out var asteroid);

            Assert.Equal(new Point(3, 4), asteroid);
            Assert.Equal(8, result);
        }
Exemplo n.º 5
0
        public void Day10Test()
        {
            Day    _day10                 = new Day10("");
            string PartOneExpected        = "Fail";
            string PartTwoExpected        = "Fail";
            Tuple <string, string> Actual = _day10.getResult();

            Assert.AreEqual(PartOneExpected, Actual.Item1);
            Assert.AreEqual(PartTwoExpected, Actual.Item2);
        }
Exemplo n.º 6
0
        public void Part02(string input, string expected)
        {
            // Arrange
            var elements = Enumerable.Range(0, 256).ToArray();

            // Act
            string actual = Day10.Part02(input, elements);

            // Assert
            Assert.Equal(expected.ToLower(), actual.ToLower());
        }
Exemplo n.º 7
0
        public void Task1()
        {
            var lenghts = new List <int> {
                3,
                4,
                1,
                5
            };

            Assert.AreEqual(12, Day10.Task1(lenghts, 5));
        }
Exemplo n.º 8
0
        public D10Form()
        {
            InitializeComponent();

            Data = new Day10();

            while (GetLogs().Max(log => log.Position.Item1) - GetLogs().Min(log => log.Position.Item1) > 90)
            {
                Tick(1);
            }
        }
Exemplo n.º 9
0
        public void Day10_A_Success()
        {
            // Arrange
            var day10 = new Day10(Path.Combine(InputFolder, "Day10.txt"));

            // Act
            var result = day10.A();

            // Assert
            Assert.Equal(2176, result);
        }
Exemplo n.º 10
0
        public void Day1_B_Success()
        {
            // Arrange
            var day10 = new Day10(Path.Combine(InputFolder, "Day10.txt"));

            // Act
            var result = day10.B();

            // Assert
            Assert.Equal(18512297918464, result);
        }
Exemplo n.º 11
0
    public static void Y2017_Day10_FindProductOfFirstTwoHashElements_Returns_Correct_Value(
        int size,
        int[] lengths,
        int expected)
    {
        // Act
        int actual = Day10.FindProductOfFirstTwoHashElements(size, lengths);

        // Assert
        actual.ShouldBe(expected);
    }
Exemplo n.º 12
0
        public void CanParse()
        {
            var results = new Day10(_testInput).Stars;

            var expected = new Star
            {
                X = 6, Y = 10, VelocityY = -1, VelocityX = -2
            };

            Assert.Equal(expected, results[3]);
        }
Exemplo n.º 13
0
        public void Day10()
        {
            var d = new Day10("Day10Test.txt");

            Assert.AreEqual(35, d.JoltageDifferenceProduct());
            Assert.AreEqual(8, d.PossibleCombinations());

            var d2 = new Day10("Day10Test2.txt");

            Assert.AreEqual(220, d2.JoltageDifferenceProduct());
            Assert.AreEqual(19208, d2.PossibleCombinations());
        }
Exemplo n.º 14
0
        private void Day10TestFull(
            Day10 day,
            int expectedCount,
            int expectedCode)
        {
            var best = day.MostVisibleAsteroids();

            Assert.AreEqual(expectedCount, best.VisibleAsteroids.Count);
            var code = day.LocationCodeForAsteroid((best.X, best.Y), best.VisibleAsteroids, 200);

            Assert.AreEqual(expectedCode, code);
        }
Exemplo n.º 15
0
        public void CannotView(int x, int y, int blockerX, int blockerY)
        {
            var map = Day10.Parse(Map);

            map.SetStationAt(1, 0);

            var blocked = map.StationCanView(x, y);

            blocked.canView.ShouldBeFalse();
            blocked.blocker.X.ShouldBe(blockerX);
            blocked.blocker.Y.ShouldBe(blockerY);
        }
Exemplo n.º 16
0
        public void Part01_Answer()
        {
            // Arrange
            var input    = Day10.ReadInput();
            var elements = Enumerable.Range(0, 256).ToArray();

            // Act
            int actual = Day10.Part01(input, elements);

            // Assert
            Assert.Equal(1935, actual);
        }
Exemplo n.º 17
0
        public void Day10Part02()
        {
            var day = new Day10();

            day.Part02("").Should().Be("a2582a3a0e66e6e86e3812dcb672a272");

            day.Part02("1,2,3").Should().Be("3efbe78a8d82f29979031a4aa0b16a9d");

            day.Part02("AoC 2017").Should().Be("33efeb34ea91902bb2f59c9920caa6cd");

            day.Part02("1,2,4").Should().Be("63960835bcdc130f0b66d7ff4f6a5a8e");
        }
Exemplo n.º 18
0
        public void Part02_Answer()
        {
            // Arrange
            var input    = Day10.ReadInput();
            var elements = Enumerable.Range(0, 256).ToArray();

            // Act
            var actual = Day10.Part02(input, elements);

            // Assert
            Assert.Equal("dc7e7dee710d4c7201ce42713e6b8359", actual);
        }
Exemplo n.º 19
0
        public void Part01()
        {
            // Arrange
            var input    = "3, 4, 1, 5";
            var elements = new[] { 0, 1, 2, 3, 4 };

            // Act
            int actual = Day10.Part01(input, elements);

            // Assert
            Assert.Equal(12, actual);
        }
Exemplo n.º 20
0
        public void PartTwoTest()
        {
            // Arrange
            var target = new Day10();

            // Act
            var result = target.Debug(Part.Two);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(133163, result);
        }
Exemplo n.º 21
0
        public void Day10_Part1_Examples()
        {
            var d = new Day10();

            Assert.AreEqual("11", d.GetSolution("1", 1));
            Assert.AreEqual("21", d.GetSolution("11", 1));
            Assert.AreEqual("1211", d.GetSolution("21", 1));
            Assert.AreEqual("111221", d.GetSolution("1211", 1));
            Assert.AreEqual("312211", d.GetSolution("111221", 1));

            Assert.AreEqual("312211", d.GetSolution("1", 5));
        }
Exemplo n.º 22
0
        public void PartOneTest()
        {
            // Arrange
            var target = new Day10();

            // Act
            var result = target.Debug(Part.One);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(161, result);
        }
Exemplo n.º 23
0
        public void ResolvePart1__Test()
        {
            Day10 day = new Day10 {
                Width = 12, Height = 10
            };

            string result = day.ResolvePart1(new string[] {
                "position=< 9,  1> velocity=< 0,  2>",
                "position=< 7,  0> velocity=<-1,  0>",
                "position=< 3, -2> velocity=<-1,  1>",
                "position=< 6, 10> velocity=<-2, -1>",
                "position=< 2, -4> velocity=< 2,  2>",
                "position=<-6, 10> velocity=< 2, -2>",
                "position=< 1,  8> velocity=< 1, -1>",
                "position=< 1,  7> velocity=< 1,  0>",
                "position=<-3, 11> velocity=< 1, -2>",
                "position=< 7,  6> velocity=<-1, -1>",
                "position=<-2,  3> velocity=< 1,  0>",
                "position=<-4,  3> velocity=< 2,  0>",
                "position=<10, -3> velocity=<-1,  1>",
                "position=< 5, 11> velocity=< 1, -2>",
                "position=< 4,  7> velocity=< 0, -1>",
                "position=< 8, -2> velocity=< 0,  1>",
                "position=<15,  0> velocity=<-2,  0>",
                "position=< 1,  6> velocity=< 1,  0>",
                "position=< 8,  9> velocity=< 0, -1>",
                "position=< 3,  3> velocity=<-1,  1>",
                "position=< 0,  5> velocity=< 0, -1>",
                "position=<-2,  2> velocity=< 2,  0>",
                "position=< 5, -2> velocity=< 1,  2>",
                "position=< 1,  4> velocity=< 2,  1>",
                "position=<-2,  7> velocity=< 2, -2>",
                "position=< 3,  6> velocity=<-1, -1>",
                "position=< 5,  0> velocity=< 1,  0>",
                "position=<-6,  0> velocity=< 2,  0>",
                "position=< 5,  9> velocity=< 1, -2>",
                "position=<14,  7> velocity=<-2,  0>",
                "position=<-3,  6> velocity=< 2, -1>",
            });

            Assert.AreEqual(
                "\r\n............" +
                "\r\n.#...#..###." +
                "\r\n.#...#...#.." +
                "\r\n.#...#...#.." +
                "\r\n.#####...#.." +
                "\r\n.#...#...#.." +
                "\r\n.#...#...#.." +
                "\r\n.#...#...#.." +
                "\r\n.#...#..###." +
                "\r\n............", result);
        }
Exemplo n.º 24
0
        public void Part2(int i, int x, int y)
        {
            const string input  = @"
.#....#####...#..
##...##.#####..##
##...#...#.#####.
..#.....X...###..
..#.#.....#....##";
            var          result = Day10.Solve2(input, 8, 3, i);

            result.X.ShouldBe(x);
            result.Y.ShouldBe(y);
        }
Exemplo n.º 25
0
        public void Part2Test(string id, int combos)
        {
            // Given
            var joltages = Input.GetLines(10, id).Select(int.Parse);

            joltages = joltages.Append(0).Append(joltages.Max() + 3);

            // When
            var counts = Day10.GetCounts(joltages);

            // Then
            Assert.Equal(combos, counts[0]);
        }
Exemplo n.º 26
0
    public override string?CalculateSolutionPartTwo()
    {
        int?[,] disk = Enumerable.Range(0, 128)
                       .Select(i => _key + '-' + i)
                       .Select(s => Day10.GetKnotHash(s))
                       .Select(h => h.SelectMany(c => c.ToHexBits().Select(b => b ? 0 : (int?)null)))
                       .To2DArray(128, 128);

        int len0  = disk.GetLength(0);
        int len1  = disk.GetLength(1);
        int count = 0;

        for (int i = 0; i < len0; i++)
        {
            for (int j = 0; j < len1; j++)
            {
                if (disk[i, j] == 0)
                {
                    SetRegion(i, j, ++count);
                }
            }
        }

        return(SolutionPartTwo = count.ToString());

        void SetRegion(int x, int y, int id)
        {
            disk[x, y] = id;

            if (x - 1 >= 0 && disk[x - 1, y] == 0)
            {
                SetRegion(x - 1, y, id);
            }

            if (y - 1 >= 0 && disk[x, y - 1] == 0)
            {
                SetRegion(x, y - 1, id);
            }

            if (x + 1 < len0 && disk[x + 1, y] == 0)
            {
                SetRegion(x + 1, y, id);
            }

            if (y + 1 < len1 && disk[x, y + 1] == 0)
            {
                SetRegion(x, y + 1, id);
            }
        }
    }
Exemplo n.º 27
0
        public void Test2()
        {
            var input = @"......#.#.
#..#.#....
..#######.
.#.#.###..
.#..#.....
..#....#.#
#..#....#.
.##.#..###
##...#..#.
.#....####";

            Day10.FindMaxVisible(input).Should().Be(33);
        }
Exemplo n.º 28
0
        public void CanRunThreeSteps()
        {
            var day10 = new Day10(_testInput);

            day10.MoveAll(3);

            var expected = new Star
            {
                X         = 0,
                Y         = 7,
                VelocityY = -1,
                VelocityX = -2
            };

            Assert.Equal(expected, day10.Stars[3]);
        }
Exemplo n.º 29
0
        public void CanRunAOneSecondStep()
        {
            var day10 = new Day10(_testInput);

            day10.MoveAll();

            var expected = new Star
            {
                X         = 4,
                Y         = 9,
                VelocityY = -1,
                VelocityX = -2
            };

            Assert.Equal(expected, day10.Stars[3]);
        }
        public void SolvePart1WithTestInput()
        {
            var testInput = @"16
10
15
5
1
11
7
19
6
12
4".Split("\r\n");
            var answer    = Day10.UseAll(Day10.ParseAdapters(testInput));

            Assert.AreEqual(7 * 5, answer);
        }