diff --git a/Advent.csproj b/Advent.csproj index 0e8f6bd..c4a020e 100644 --- a/Advent.csproj +++ b/Advent.csproj @@ -10,6 +10,9 @@ + + PreserveNewest + PreserveNewest diff --git a/Advent.csproj.DotSettings b/Advent.csproj.DotSettings index 1e6fa81..6f4447f 100644 --- a/Advent.csproj.DotSettings +++ b/Advent.csproj.DotSettings @@ -1,5 +1,6 @@  True + True True True True diff --git a/Day10/Day10.cs b/Day10/Day10.cs new file mode 100644 index 0000000..958e210 --- /dev/null +++ b/Day10/Day10.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.IO; + +namespace Advent +{ + public static class Day10 + { + public static void Execute() + { + var lines = File.ReadAllLines(@".\Day10\input.txt"); + + var y = 0; + + var asteroids = new List>(); + + foreach (var line in lines) + { + var x = 0; + + foreach (var cell in line.ToCharArray()) + { + if (cell == '#') + asteroids.Add(new Tuple(x, y)); + + x++; + } + + y++; + } + + var bestLocation = new Tuple(-1, -1); + var bestCount = 0; + + foreach (var potentialAsteroid in asteroids) + { + var angles = new HashSet(); + + foreach (var asteroid in asteroids) + { + if (asteroid.Equals(potentialAsteroid)) + continue; + + var angle = Math.Atan2(asteroid.Item2 - potentialAsteroid.Item2, asteroid.Item1 - potentialAsteroid.Item1); + + if (!angles.Contains(angle)) + angles.Add(angle); + } + + if (angles.Count > bestCount) + { + bestCount = angles.Count; + bestLocation = potentialAsteroid; + } + } + + Console.WriteLine($"{bestLocation.Item1},{bestLocation.Item2} = {bestCount}"); + } + } +} diff --git a/Day10/input.txt b/Day10/input.txt new file mode 100644 index 0000000..b1ebbd8 --- /dev/null +++ b/Day10/input.txt @@ -0,0 +1,26 @@ +.##.#.#....#.#.#..##..#.#. +#.##.#..#.####.##....##.#. +###.##.##.#.#...#..###.... +####.##..###.#.#...####..# +..#####..#.#.#..#######..# +.###..##..###.####.####### +.##..##.###..##.##.....### +#..#..###..##.#...#..####. +....#.#...##.##....#.#..## +..#.#.###.####..##.###.#.# +.#..##.#####.##.####..#.#. +#..##.#.#.###.#..##.##.... +#.#.##.#.##.##......###.#. +#####...###.####..#.##.... +.#####.#.#..#.##.#.#...### +.#..#.##.#.#.##.#....###.# +.......###.#....##.....### +#..#####.#..#..##..##.#.## +##.#.###..######.###..#..# +#.#....####.##.###....#### +..#.#.#.########.....#.#.# +.##.#.#..#...###.####..##. +##...###....#.##.##..#.... +..##.##.##.#######..#...#. +.###..#.#..#...###..###.#. +#..#..#######..#.#..#..#.# \ No newline at end of file diff --git a/Program.cs b/Program.cs index 3f7b452..8d89d84 100644 --- a/Program.cs +++ b/Program.cs @@ -12,7 +12,8 @@ //Day6.Execute(); //Day7.Execute(); //Day8.Execute(); - Day9.Execute(); + //Day9.Execute(); + Day10.Execute(); } } }