day 6
This commit is contained in:
parent
419f225bd0
commit
17506f7a29
|
@ -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}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,9 @@
|
||||||
<None Update="input\day5.in">
|
<None Update="input\day5.in">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="input\day6.in">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue