diff options
author | Ben Harris <ben@tilde.team> | 2019-12-06 02:02:01 -0500 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2019-12-06 02:02:01 -0500 |
commit | 17506f7a294d1bd6367b81306210fe6623ec137c (patch) | |
tree | ae733fd88e94fbe1e3491b34337d96326340cf18 /Day6.cs | |
parent | 419f225bd05629562f656ffb31beede5417af780 (diff) |
day 6
Diffstat (limited to 'Day6.cs')
-rw-r--r-- | Day6.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Day6.cs b/Day6.cs new file mode 100644 index 0000000..de59f99 --- /dev/null +++ b/Day6.cs @@ -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}"; + } + } +} |