about summary refs log tree commit diff
path: root/Day10.cs
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2020-12-16 18:06:36 -0500
committerBen Harris <ben@tilde.team>2020-12-16 18:06:36 -0500
commitcb10768fa14c4b6ec19d050e13a0c3e00c152874 (patch)
tree2da56b45700f5dd1bde994cbeae04f18424a17c3 /Day10.cs
parent837527d487c7e232b36dd87c95a15b7852f2e057 (diff)
move project to subdirectory and add unit testing
day 13 is removed from the test so it doesn't take 4 years
Diffstat (limited to 'Day10.cs')
-rw-r--r--Day10.cs73
1 files changed, 0 insertions, 73 deletions
diff --git a/Day10.cs b/Day10.cs
deleted file mode 100644
index 376e427..0000000
--- a/Day10.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using aoc2019.lib;
-
-namespace aoc2019
-{
-    internal sealed class Day10 : Day
-    {
-        private readonly HashSet<(int x, int y)> asteroids;
-        private (int x, int y) best = (x: -1, y: -1);
-        private int bestCanSee;
-
-        public Day10() : base(10, "Monitoring Station")
-        {
-            asteroids = Input
-                .Select((r, y) => r.Select((c, x) => (x, y, isAsteroid: c == '#')).ToArray())
-                .SelectMany(r => r)
-                .Where(a => a.isAsteroid)
-                .Select(a => (a.x, a.y))
-                .ToHashSet();
-        }
-
-        protected override string Part1()
-        {
-            foreach (var asteroid in asteroids)
-            {
-                var canSee = asteroids
-                    .Except(new[] {asteroid})
-                    .Select(a => (x: a.x - asteroid.x, y: a.y - asteroid.y))
-                    .GroupBy(a => Math.Atan2(a.y, a.x))
-                    .Count();
-
-                if (canSee > bestCanSee)
-                {
-                    best = asteroid;
-                    bestCanSee = canSee;
-                }
-            }
-
-            return $"{bestCanSee}";
-        }
-
-        protected override string Part2()
-        {
-            static IEnumerable<(int x, int y, double angle, double dist)> GetValue(
-                Queue<(int x, int y, double angle, double dist)> q)
-            {
-                if (q.Count > 0) yield return q.Dequeue();
-            }
-
-            return asteroids
-                .Where(a => a != best)
-                .Select(a =>
-                {
-                    var xDist = a.x - best.x;
-                    var yDist = a.y - best.y;
-                    var angle = Math.Atan2(xDist, yDist);
-                    return (a.x, a.y, angle, dist: Math.Sqrt(xDist * xDist + yDist * yDist));
-                })
-                .ToLookup(a => a.angle)
-                .OrderByDescending(a => a.Key)
-                .Select(a => new Queue<(int x, int y, double angle, double dist)>(a.OrderBy(b => b.dist)))
-                .Repeat()
-                .SelectMany(GetValue)
-                .Skip(199)
-                .Take(1)
-                .Select(a => a.x * 100 + a.y)
-                .Single()
-                .ToString();
-        }
-    }
-}
\ No newline at end of file