diff options
Diffstat (limited to 'aoc2021/Day10.cs')
-rw-r--r-- | aoc2021/Day10.cs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/aoc2021/Day10.cs b/aoc2021/Day10.cs new file mode 100644 index 0000000..4907a80 --- /dev/null +++ b/aoc2021/Day10.cs @@ -0,0 +1,63 @@ +using System.Collections; + +namespace aoc2021; + +/// <summary> +/// Day 10: <see href="https://adventofcode.com/2021/day/10"/> +/// </summary> +public sealed class Day10 : Day +{ + private readonly List<string> _input; + private readonly char[] _openers = { '(', '[', '{', '<' }; + private readonly char[] _closers = { ')', ']', '}', '>' }; + + private readonly Dictionary<char, int> _scores = new() + { + { ')', 3 }, + { ']', 57 }, + { '}', 1197 }, + { '>', 25137 } + }; + + private readonly Dictionary<char, int> _scoresClosing = new() + { + { '(', 1 }, + { '[', 2 }, + { '{', 3 }, + { '<', 4 } + }; + + public Day10() : base(10, "Syntax Scoring") + { + _input = Input.ToList(); + } + + public override string Part1() + { + var s = new Stack<char>(); + var score = 0; + foreach (var line in _input) + { + foreach (var c in line) + { + if (_openers.Contains(c)) + { + s.Push(c); + } + else + { + var y = s.Pop(); + if (Math.Abs(y - c) <= 3) continue; + score += _scores[c]; + break; + } + } + } + + return score.ToString(); + } + + public override string Part2() + { + } +} |