Example #1
0
        public void Test_DayTen_PartOne()
        {
            var testFile = Path.Combine(TestHelper.TestDir, "Day10.Input.txt");
            var map      = new AsteroidMap(testFile);
            var best     = map.GetBestAsteroid();

            Assert.IsTrue(best.Item2 == 319);
        }
Example #2
0
        public void ShouldCorrectlyGetPart1Solution()
        {
            AsteroidMap map      = new AsteroidMap(@"Inputs\Day10Input.txt");
            Asteroid    asteroid = map.GetBestAsteroid();

            Assert.Equal(280, asteroid.AsteroidsVisible);
            Assert.Equal(20, asteroid.X);
            Assert.Equal(18, asteroid.Y);
        }
        public void ShouldCorrectlyCalculateExample5()
        {
            AsteroidMap map = new AsteroidMap(@"Inputs\Day10Example5Input.txt");

            Asteroid asteroid = map.GetBestAsteroid();

            Assert.Equal(11, asteroid.X);
            Assert.Equal(13, asteroid.Y);
            Assert.Equal(210, asteroid.AsteroidsVisible);
        }
Example #4
0
        public void Test_KnownVapourization()
        {
            var map   = new AsteroidMap(Path.Combine(TestHelper.TestDir, "Day10.Test4.txt"));
            var laser = new Asteroid(11, 13);
            var order = map.GetVapourizationOrder(laser);

            var known = new Asteroid(8, 2);

            Assert.IsTrue(order.Last().Equals(known));
        }
Example #5
0
        public void ShouldCorrectlyGetPart2Solution()
        {
            AsteroidMap map      = new AsteroidMap(@"Inputs\Day10Input.txt");
            Asteroid    asteroid = map.GetBestAsteroid();

            Asteroid answer = map.GetOrderOfDestruction(asteroid).Skip(199).First();

            Assert.Equal(7, answer.X);
            Assert.Equal(6, answer.Y);
        }
        public void ShouldCorrectlyCalculateExample1_Part1()
        {
            AsteroidMap map      = new AsteroidMap(@"Inputs\Day10Example1Input.txt");
            Asteroid    asteroid = map.Asteroids.Where(x => x.X == 3 && x.Y == 4).First();

            Assert.Equal(4, asteroid.Y);
            Assert.Equal(3, asteroid.X);

            map.UpdateAsteroidsInFOV(asteroid);
            Assert.Equal(8, asteroid.AsteroidsVisible);
        }
Example #7
0
        public void Intersects(int x1, int y1, int x2, int y2, int[] pointsFlat)
        {
            var points = pointsFlat.Where((_, i) => i % 2 == 0)
                         .Zip(pointsFlat.Where((_, i) => i % 2 == 1)).ToArray();
            var intersects = AsteroidMap.Intersects(x1, y1, x2, y2).ToArray();

            Assert.Equal(points.Length, intersects.Length);
            for (int i = 0; i < points.Length; i++)
            {
                Assert.Equal(points[i], intersects[i]);
            }
        }
Example #8
0
 public void Test_KnownMaps()
 {
     foreach (var test in KnownMaps)
     {
         //< Make the map
         var map = new AsteroidMap(test.File);
         //< Get the best asteroid
         var best = map.GetBestAsteroid();
         //< Ensure we ain't f**k up
         Assert.IsTrue(best.Item1.Equals(test.Asteroid));
         Assert.IsTrue(best.Item2 == test.CountVisible);
     }
 }
Example #9
0
        public void SolvePart2()
        {
            var input = System.IO.File.ReadAllLines("../../../input/day_10.txt");

            AsteroidMap map = new AsteroidMap(input);

            map.LoadAsteroidsPerAngle(new Point(23, 29));

            var p = AsteroidBlaster.BlastAsteroids(map.AsteroidsPerAngle, 200);

            int result = (p.x * 100) + p.y;

            Assert.Equal(1110, result);
        }
Example #10
0
        public void Test_DayTen_PartTwo()
        {
            var testFile = Path.Combine(TestHelper.TestDir, "Day10.Input.txt");
            var map      = new AsteroidMap(testFile);
            var best     = map.GetBestAsteroid();

            //< Set the laser at the 'best' point and get the vapourization order
            var order = map.GetVapourizationOrder(best.Item1);

            //< Get the 'test' value
            var last      = order.Last();
            var testValue = last.X * 100.0 + last.Y;

            Assert.IsTrue(testValue == 517);
        }
Example #11
0
        public void Part3()
        {
            string[] input = new string[]
            {
                "#.#",
                ".#.",
                "#.#",
            };

            var map = new AsteroidMap(input);

            int visible = map.CountVisibleAsteroids(new Point(1, 1));

            Assert.Equal(4, visible);
        }
Example #12
0
        public void Part1()
        {
            string[] input = new string[]
            {
                ".#..#",
                ".....",
                "#####",
                "....#",
                "...##"
            };

            var map = new AsteroidMap(input);

            int visible = map.CountVisibleAsteroids(new Point(3, 4));

            Assert.Equal(8, visible);
        }
Example #13
0
        public void SolvePart1()
        {
            var input = System.IO.File.ReadAllLines("../../../input/day_10.txt");

            AsteroidMap map = new AsteroidMap(input);

            int   mostVisible = 0;
            Point location    = new Point();

            foreach (Point asteroid in map.AsteroidCoordinates)
            {
                int visible = map.CountVisibleAsteroids(asteroid);

                if (visible > mostVisible)
                {
                    mostVisible = visible;
                    location    = asteroid;
                }
            }

            Assert.Equal(263, mostVisible);
            Assert.Equal(23, location.x);
            Assert.Equal(29, location.y);
        }
Example #14
0
        public void Part5()
        {
            string[] input = new string[]
            {
                ".#..##.###...#######",
                "##.############..##.",
                ".#.######.########.#",
                ".###.#######.####.#.",
                "#####.##.#.##.###.##",
                "..#####..#.#########",
                "####################",
                "#.####....###.#.#.##",
                "##.#################",
                "#####.##.###..####..",
                "..######..##.#######",
                "####.##.####...##..#",
                ".#####..#.######.###",
                "##...#.##########...",
                "#.##########.#######",
                ".####.#.###.###.#.##",
                "....##.##.###..#####",
                ".#.#.###########.###",
                "#.#.#.#####.####.###",
                "###.##.####.##.#..##"
            };

            var map = new AsteroidMap(input);

            int visible = map.CountVisibleAsteroids(new Point(11, 13));

            var p = AsteroidBlaster.BlastAsteroids(map.AsteroidsPerAngle, 200);

            Assert.Equal(210, visible);
            Assert.Equal(8, p.x);
            Assert.Equal(2, p.y);
        }
Example #15
0
        public void ShouldCorrectlyCalculatePart2_Example2()
        {
            /**
             * Dynamically generated from
             * $s = @(
             *     "The 1st asteroid to be vaporized is at 11,12."
             *     "The 2nd asteroid to be vaporized is at 12,1."
             *     "The 3rd asteroid to be vaporized is at 12,2."
             *     "The 10th asteroid to be vaporized is at 12,8."
             *     "The 20th asteroid to be vaporized is at 16,0."
             *     "The 50th asteroid to be vaporized is at 16,9."
             *     "The 100th asteroid to be vaporized is at 10,16."
             *     "The 199th asteroid to be vaporized is at 9,6."
             *     "The 200th asteroid to be vaporized is at 8,2."
             *     "The 201st asteroid to be vaporized is at 10,9."
             *     "The 299th and final asteroid to be vaporized is at 11,1"
             * )
             *
             *
             * foreach ($line in $s) {
             *     if ($line -Match "([0-9]{1,3}).*at ([0-9]{1,2}),([0-9]{1,2}).*") {
             *         $index = [int]$Matches[1] - 1
             *         $x = $Matches[2]
             *         $y = $Matches[3]
             *
             *         Write-Output "Assert.Equal($x, destructionOrder[$index].X);"
             *         Write-Output "Assert.Equal($y, destructionOrder[$index].Y);"
             *         Write-Output ""
             *     }
             * }
             **/

            AsteroidMap     map              = new AsteroidMap(@"Inputs\Day10Example5Input.txt");
            Asteroid        asteroid         = map.Asteroids.Where(x => x.X == 11 && x.Y == 13).First();
            List <Asteroid> destructionOrder = map.GetOrderOfDestruction(asteroid).ToList();


            Assert.Equal(11, destructionOrder[0].X);
            Assert.Equal(12, destructionOrder[0].Y);

            Assert.Equal(12, destructionOrder[1].X);
            Assert.Equal(1, destructionOrder[1].Y);

            Assert.Equal(12, destructionOrder[2].X);
            Assert.Equal(2, destructionOrder[2].Y);

            Assert.Equal(12, destructionOrder[9].X);
            Assert.Equal(8, destructionOrder[9].Y);

            Assert.Equal(16, destructionOrder[19].X);
            Assert.Equal(0, destructionOrder[19].Y);

            Assert.Equal(16, destructionOrder[49].X);
            Assert.Equal(9, destructionOrder[49].Y);

            Assert.Equal(10, destructionOrder[99].X);
            Assert.Equal(16, destructionOrder[99].Y);

            Assert.Equal(9, destructionOrder[198].X);
            Assert.Equal(6, destructionOrder[198].Y);

            Assert.Equal(8, destructionOrder[199].X);
            Assert.Equal(2, destructionOrder[199].Y);

            Assert.Equal(10, destructionOrder[200].X);
            Assert.Equal(9, destructionOrder[200].Y);

            Assert.Equal(11, destructionOrder[298].X);
            Assert.Equal(1, destructionOrder[298].Y);
        }
Example #16
0
 void Awake() {
     instance = this;
     scrollArea.enabled = false;
 }
Example #17
0
        public void ShouldCorrectlyCalculateExample1()
        {
            /*
             * Autogenerated using the powershell
             *   $s = @(
             *       ".#....###24...#.."
             *       "##...##.13#67..9#"
             *       "##...#...5.8####."
             *       "..#.....X...###.."
             *       "..#.#.....#....##"
             *   )
             *
             *   for ($i = 0; $i -lt $s.Count; $i++) {
             *       for ($j = 0; $j -lt $s[$i].Length; $j++) {
             *           if ($s[$i][$j] -Match "[0-9]") {
             *               $val = $matches[0] - 1
             *               Write-Host "Assert.Equal($j, destructionOrder[$val].X);"
             *               Write-Host "Assert.Equal($i, destructionOrder[$val].Y);"
             *               Write-Host
             *           }
             *       }
             *   }
             **/

            AsteroidMap     map              = new AsteroidMap(@"Inputs\Day10ExamplePart2_1Input.txt");
            Asteroid        asteroid         = map.Asteroids.Where(x => x.X == 8 && x.Y == 3).First();
            List <Asteroid> destructionOrder = map.GetOrderOfDestruction(asteroid).ToList();

            Assert.Equal(8, destructionOrder[0].X);
            Assert.Equal(1, destructionOrder[0].Y);

            Assert.Equal(9, destructionOrder[1].X);
            Assert.Equal(0, destructionOrder[1].Y);

            Assert.Equal(9, destructionOrder[2].X);
            Assert.Equal(1, destructionOrder[2].Y);

            Assert.Equal(10, destructionOrder[3].X);
            Assert.Equal(0, destructionOrder[3].Y);

            Assert.Equal(8, destructionOrder[0].X);
            Assert.Equal(1, destructionOrder[0].Y);

            Assert.Equal(8, destructionOrder[0].X);
            Assert.Equal(1, destructionOrder[0].Y);

            Assert.Equal(9, destructionOrder[1].X);
            Assert.Equal(0, destructionOrder[1].Y);

            Assert.Equal(9, destructionOrder[2].X);
            Assert.Equal(1, destructionOrder[2].Y);

            Assert.Equal(10, destructionOrder[3].X);
            Assert.Equal(0, destructionOrder[3].Y);

            Assert.Equal(9, destructionOrder[4].X);
            Assert.Equal(2, destructionOrder[4].Y);

            Assert.Equal(11, destructionOrder[5].X);
            Assert.Equal(1, destructionOrder[5].Y);

            Assert.Equal(12, destructionOrder[6].X);
            Assert.Equal(1, destructionOrder[6].Y);

            Assert.Equal(11, destructionOrder[7].X);
            Assert.Equal(2, destructionOrder[7].Y);

            Assert.Equal(15, destructionOrder[8].X);
            Assert.Equal(1, destructionOrder[8].Y);

            Assert.Equal(12, destructionOrder[9].X);
            Assert.Equal(2, destructionOrder[9].Y);

            Assert.Equal(13, destructionOrder[10].X);
            Assert.Equal(2, destructionOrder[10].Y);

            Assert.Equal(14, destructionOrder[11].X);
            Assert.Equal(2, destructionOrder[11].Y);

            Assert.Equal(15, destructionOrder[12].X);
            Assert.Equal(2, destructionOrder[12].Y);

            Assert.Equal(12, destructionOrder[13].X);
            Assert.Equal(3, destructionOrder[13].Y);

            Assert.Equal(16, destructionOrder[14].X);
            Assert.Equal(4, destructionOrder[14].Y);

            Assert.Equal(15, destructionOrder[15].X);
            Assert.Equal(4, destructionOrder[15].Y);

            Assert.Equal(10, destructionOrder[16].X);
            Assert.Equal(4, destructionOrder[16].Y);

            Assert.Equal(4, destructionOrder[17].X);
            Assert.Equal(4, destructionOrder[17].Y);

            Assert.Equal(2, destructionOrder[18].X);
            Assert.Equal(4, destructionOrder[18].Y);

            Assert.Equal(2, destructionOrder[19].X);
            Assert.Equal(3, destructionOrder[19].Y);

            Assert.Equal(0, destructionOrder[20].X);
            Assert.Equal(2, destructionOrder[20].Y);

            Assert.Equal(1, destructionOrder[21].X);
            Assert.Equal(2, destructionOrder[21].Y);

            Assert.Equal(0, destructionOrder[22].X);
            Assert.Equal(1, destructionOrder[22].Y);

            Assert.Equal(1, destructionOrder[23].X);
            Assert.Equal(1, destructionOrder[23].Y);

            Assert.Equal(5, destructionOrder[24].X);
            Assert.Equal(2, destructionOrder[24].Y);

            Assert.Equal(1, destructionOrder[25].X);
            Assert.Equal(0, destructionOrder[25].Y);

            Assert.Equal(5, destructionOrder[26].X);
            Assert.Equal(1, destructionOrder[26].Y);

            Assert.Equal(6, destructionOrder[27].X);
            Assert.Equal(1, destructionOrder[27].Y);

            Assert.Equal(6, destructionOrder[28].X);
            Assert.Equal(0, destructionOrder[28].Y);

            Assert.Equal(7, destructionOrder[29].X);
            Assert.Equal(0, destructionOrder[29].Y);

            Assert.Equal(8, destructionOrder[30].X);
            Assert.Equal(0, destructionOrder[30].Y);

            Assert.Equal(10, destructionOrder[31].X);
            Assert.Equal(1, destructionOrder[31].Y);

            Assert.Equal(14, destructionOrder[32].X);
            Assert.Equal(0, destructionOrder[32].Y);

            Assert.Equal(16, destructionOrder[33].X);
            Assert.Equal(1, destructionOrder[33].Y);

            Assert.Equal(13, destructionOrder[34].X);
            Assert.Equal(3, destructionOrder[34].Y);

            Assert.Equal(14, destructionOrder[35].X);
            Assert.Equal(3, destructionOrder[35].Y);
        }