mirror of
https://github.com/ckaczor/Advent2019.git
synced 2026-01-13 17:22:15 -05:00
Day 10 - Part 1
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Day10\input.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Day1\input.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day1/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day10/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day2/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day3/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day4/@EntryIndexedValue">True</s:Boolean>
|
||||
|
||||
60
Day10/Day10.cs
Normal file
60
Day10/Day10.cs
Normal file
@@ -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<Tuple<int, int>>();
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var x = 0;
|
||||
|
||||
foreach (var cell in line.ToCharArray())
|
||||
{
|
||||
if (cell == '#')
|
||||
asteroids.Add(new Tuple<int, int>(x, y));
|
||||
|
||||
x++;
|
||||
}
|
||||
|
||||
y++;
|
||||
}
|
||||
|
||||
var bestLocation = new Tuple<int, int>(-1, -1);
|
||||
var bestCount = 0;
|
||||
|
||||
foreach (var potentialAsteroid in asteroids)
|
||||
{
|
||||
var angles = new HashSet<double>();
|
||||
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Day10/input.txt
Normal file
26
Day10/input.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
.##.#.#....#.#.#..##..#.#.
|
||||
#.##.#..#.####.##....##.#.
|
||||
###.##.##.#.#...#..###....
|
||||
####.##..###.#.#...####..#
|
||||
..#####..#.#.#..#######..#
|
||||
.###..##..###.####.#######
|
||||
.##..##.###..##.##.....###
|
||||
#..#..###..##.#...#..####.
|
||||
....#.#...##.##....#.#..##
|
||||
..#.#.###.####..##.###.#.#
|
||||
.#..##.#####.##.####..#.#.
|
||||
#..##.#.#.###.#..##.##....
|
||||
#.#.##.#.##.##......###.#.
|
||||
#####...###.####..#.##....
|
||||
.#####.#.#..#.##.#.#...###
|
||||
.#..#.##.#.#.##.#....###.#
|
||||
.......###.#....##.....###
|
||||
#..#####.#..#..##..##.#.##
|
||||
##.#.###..######.###..#..#
|
||||
#.#....####.##.###....####
|
||||
..#.#.#.########.....#.#.#
|
||||
.##.#.#..#...###.####..##.
|
||||
##...###....#.##.##..#....
|
||||
..##.##.##.#######..#...#.
|
||||
.###..#.#..#...###..###.#.
|
||||
#..#..#######..#.#..#..#.#
|
||||
@@ -12,7 +12,8 @@
|
||||
//Day6.Execute();
|
||||
//Day7.Execute();
|
||||
//Day8.Execute();
|
||||
Day9.Execute();
|
||||
//Day9.Execute();
|
||||
Day10.Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user