mirror of
https://github.com/ckaczor/Advent2019.git
synced 2026-02-16 10:48:30 -05:00
Day 6
This commit is contained in:
@@ -19,6 +19,12 @@
|
|||||||
<None Update="Day3\input.txt">
|
<None Update="Day3\input.txt">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="Day6\input.txt">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Day6\test-input.txt">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day2/@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/=day3/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day4/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day4/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day5/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day5/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day6/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||||
104
Day6/Day6.cs
Normal file
104
Day6/Day6.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Advent
|
||||||
|
{
|
||||||
|
public static class Day6
|
||||||
|
{
|
||||||
|
private static readonly Dictionary<string, MapObject> Orbits = new Dictionary<string, MapObject>
|
||||||
|
{
|
||||||
|
["COM"] = new MapObject { Name = "COM" }
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void Execute()
|
||||||
|
{
|
||||||
|
var lines = File.ReadAllLines(@".\Day6\input.txt");
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
var lineParts = line.Split(')');
|
||||||
|
|
||||||
|
var orbitObject = lineParts[1];
|
||||||
|
|
||||||
|
Orbits[orbitObject] = new MapObject { Name = orbitObject };
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
var lineParts = line.Split(')');
|
||||||
|
|
||||||
|
var orbitCenter = lineParts[0];
|
||||||
|
var orbitObject = lineParts[1];
|
||||||
|
|
||||||
|
Orbits[orbitObject].Parent = Orbits[orbitCenter];
|
||||||
|
}
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
foreach (var orbitKey in Orbits.Keys)
|
||||||
|
{
|
||||||
|
var orbitObject = Orbits[orbitKey];
|
||||||
|
|
||||||
|
while (orbitObject.Parent != null)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
orbitObject = orbitObject.Parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine(count);
|
||||||
|
|
||||||
|
var santaPath = GetPath("SAN");
|
||||||
|
var myPath = GetPath("YOU");
|
||||||
|
|
||||||
|
var commonPoint = string.Empty;
|
||||||
|
|
||||||
|
foreach (var key in myPath)
|
||||||
|
{
|
||||||
|
if (santaPath.Contains(key))
|
||||||
|
{
|
||||||
|
commonPoint = key;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var jumpCount = 0;
|
||||||
|
|
||||||
|
foreach (var key in myPath)
|
||||||
|
{
|
||||||
|
if (key == commonPoint)
|
||||||
|
break;
|
||||||
|
|
||||||
|
jumpCount++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var key in santaPath)
|
||||||
|
{
|
||||||
|
if (key == commonPoint)
|
||||||
|
break;
|
||||||
|
|
||||||
|
jumpCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine(jumpCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<string> GetPath(string startKey)
|
||||||
|
{
|
||||||
|
var path = new List<string>();
|
||||||
|
|
||||||
|
var orbitObject = Orbits[startKey];
|
||||||
|
|
||||||
|
while (orbitObject.Parent != null)
|
||||||
|
{
|
||||||
|
orbitObject = orbitObject.Parent;
|
||||||
|
|
||||||
|
path.Add(orbitObject.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Day6/MapObject.cs
Normal file
8
Day6/MapObject.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Advent
|
||||||
|
{
|
||||||
|
public class MapObject
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public MapObject Parent { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
1062
Day6/input.txt
Normal file
1062
Day6/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
13
Day6/test-input.txt
Normal file
13
Day6/test-input.txt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
COM)B
|
||||||
|
B)C
|
||||||
|
C)D
|
||||||
|
D)E
|
||||||
|
E)F
|
||||||
|
B)G
|
||||||
|
G)H
|
||||||
|
D)I
|
||||||
|
E)J
|
||||||
|
J)K
|
||||||
|
K)L
|
||||||
|
K)YOU
|
||||||
|
I)SAN
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
//Day2.Execute();
|
//Day2.Execute();
|
||||||
//Day3.Execute();
|
//Day3.Execute();
|
||||||
//Day4.Execute();
|
//Day4.Execute();
|
||||||
Day5.Execute();
|
//Day5.Execute();
|
||||||
|
Day6.Execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user