This commit is contained in:
Ben Harris 2019-12-06 02:02:01 -05:00
parent 419f225bd0
commit 17506f7a29
3 changed files with 1152 additions and 0 deletions

39
Day6.cs Normal file
View File

@ -0,0 +1,39 @@
using System.Collections.Generic;
using System.Linq;
namespace aoc2019
{
internal class Day6 : Day
{
public override int DayNumber => 6;
private readonly Dictionary<string, string> input;
public Day6()
{
input = Input.ToDictionary(i => i.Split(')')[1], i => i.Split(')')[0]);
}
private List<string> GetParents(string obj)
{
var res = new List<string>();
for (var curr = obj; curr != "COM"; curr = input[curr])
res.Add(curr);
res.Add("COM");
return res;
}
public override string Part1()
{
return $"{input.Keys.Sum(o => GetParents(o).Count - 1)}";
}
public override string Part2()
{
List<string> you = GetParents("YOU");
List<string> san = GetParents("SAN");
int common = 1;
for (; you[^common] == san[^common]; common++);
return $"{you.Count + san.Count - common * 2}";
}
}
}

View File

@ -21,6 +21,9 @@
<None Update="input\day5.in">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="input\day6.in">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

1110
input/day6.in Normal file

File diff suppressed because it is too large Load Diff