day 10 part 1
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
663d31564a
commit
6d22bf07fc
|
@ -0,0 +1,74 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace aoc2019
|
||||||
|
{
|
||||||
|
internal class Day10 : Day
|
||||||
|
{
|
||||||
|
public override int DayNumber => 10;
|
||||||
|
|
||||||
|
private readonly List<Point> asteroids = new List<Point>();
|
||||||
|
private Point best = new Point(-1, -1);
|
||||||
|
private IGrouping<double, Point>[] bestgroups;
|
||||||
|
private int bestcansee;
|
||||||
|
|
||||||
|
public Day10()
|
||||||
|
{
|
||||||
|
var starmap = Input.Select(x => x.Select(y => y == '#').ToArray()).ToArray();
|
||||||
|
|
||||||
|
for (var i = 0; i < starmap.Length; i++)
|
||||||
|
for (var j = 0; j < starmap[i].Length; j++)
|
||||||
|
if (starmap[i][j])
|
||||||
|
asteroids.Add(new Point(i, j));
|
||||||
|
|
||||||
|
foreach (var asteroid in asteroids)
|
||||||
|
{
|
||||||
|
var groups = asteroids.Except(new[] { asteroid })
|
||||||
|
.Select(a => new Point(a.X - asteroid.X, a.Y - asteroid.Y))
|
||||||
|
.GroupBy(a => Math.Atan2(a.Y, a.X))
|
||||||
|
.ToArray();
|
||||||
|
var cansee = groups.Count();
|
||||||
|
|
||||||
|
if (cansee > bestcansee)
|
||||||
|
{
|
||||||
|
best = asteroid;
|
||||||
|
bestcansee = cansee;
|
||||||
|
bestgroups = groups;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Part1()
|
||||||
|
{
|
||||||
|
return $"{bestcansee}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Part2()
|
||||||
|
{
|
||||||
|
var removals = bestgroups
|
||||||
|
.Select(g => new {
|
||||||
|
Angle = g.Key,
|
||||||
|
Targets = new Queue<Point>(g.OrderBy(a =>
|
||||||
|
Math.Sqrt(Math.Pow(a.X, 2) + Math.Pow(a.Y, 2))
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.OrderBy(g => g.Angle > Math.PI / 2)
|
||||||
|
.ThenByDescending(g => g.Angle);
|
||||||
|
|
||||||
|
var removed = 0;
|
||||||
|
while (true)
|
||||||
|
foreach (var removal in removals)
|
||||||
|
if (removal.Targets.Count > 0)
|
||||||
|
{
|
||||||
|
var toremove = removal.Targets.Dequeue();
|
||||||
|
removed++;
|
||||||
|
if (removed == 200)
|
||||||
|
{
|
||||||
|
return $"{(toremove.X * 100) + toremove.Y}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ namespace aoc2019
|
||||||
private static IEnumerable<Day> GetDays() =>
|
private static IEnumerable<Day> GetDays() =>
|
||||||
Assembly.GetExecutingAssembly().GetTypes()
|
Assembly.GetExecutingAssembly().GetTypes()
|
||||||
.Where(t => t.BaseType == typeof(Day))
|
.Where(t => t.BaseType == typeof(Day))
|
||||||
.Select(t => (Day)Activator.CreateInstance(t));
|
.Select(t => (Day)Activator.CreateInstance(t))
|
||||||
|
.OrderBy(d => d.DayNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,9 @@
|
||||||
<None Update="input\day9.in">
|
<None Update="input\day9.in">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="input\day10.in">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
##.##..#.####...#.#.####
|
||||||
|
##.###..##.#######..##..
|
||||||
|
..######.###.#.##.######
|
||||||
|
.#######.####.##.#.###.#
|
||||||
|
..#...##.#.....#####..##
|
||||||
|
#..###.#...#..###.#..#..
|
||||||
|
###..#.##.####.#..##..##
|
||||||
|
.##.##....###.#..#....#.
|
||||||
|
########..#####..#######
|
||||||
|
##..#..##.#..##.#.#.#..#
|
||||||
|
##.#.##.######.#####....
|
||||||
|
###.##...#.##...#.######
|
||||||
|
###...##.####..##..#####
|
||||||
|
##.#...#.#.....######.##
|
||||||
|
.#...####..####.##...##.
|
||||||
|
#.#########..###..#.####
|
||||||
|
#.##..###.#.######.#####
|
||||||
|
##..##.##...####.#...##.
|
||||||
|
###...###.##.####.#.##..
|
||||||
|
####.#.....###..#.####.#
|
||||||
|
##.####..##.#.##..##.#.#
|
||||||
|
#####..#...####..##..#.#
|
||||||
|
.##.##.##...###.##...###
|
||||||
|
..###.########.#.###..#.
|
Loading…
Reference in New Issue