This commit is contained in:
Ben Harris 2021-12-10 00:43:57 -05:00
parent c19e4799a7
commit cdf3674e4e
4 changed files with 177 additions and 0 deletions

View File

@ -13,6 +13,7 @@ public class DayTests
[DataRow(typeof(Day07), "345035", "97038163")]
[DataRow(typeof(Day08), "362", "1020159")]
[DataRow(typeof(Day09), "478", "1327014")]
[DataRow(typeof(Day10), "288291", "")]
public void CheckAllDays(Type dayType, string part1, string part2)
{
var s = Stopwatch.StartNew();
@ -52,6 +53,7 @@ public class DayTests
[DataRow(typeof(Day07), "37", "168")]
[DataRow(typeof(Day08), "26", "61229")]
[DataRow(typeof(Day09), "15", "1134")]
[DataRow(typeof(Day10), "26397", "288957")]
public void CheckTestInputs(Type dayType, string part1, string part2)
{
Day.UseTestInput = true;

63
aoc2021/Day10.cs Normal file
View File

@ -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()
{
}
}

102
aoc2021/input/day10.in Normal file
View File

@ -0,0 +1,102 @@
[<[{<[(([<[[{[()()]}]{<<<>[]>[()[]]>{(<>[]){<>[]}}}]<{(<()<>>{()<>})(<()>)}([{()[]}](<()<>>
<[(<({[<(<<({({}[])[<>]}[<<>{}>[()()]])>>)>]})>{[([({[{{<[[]{}]{{}}><{()[]}[{}]>}}{{[<<>()>((){})
{<({([<([[<<[(<>())({}{})](<()()>{{}})>(([[]{}]<[][]>){<{}>{<>{}}})>]][[((<[<>()]<<>[]>>{{()[]}{[]{}
([{({<<{<<<{([{}[]]([]())){[(){}]}}{[<{}()>(<>[])]}][({[()<>][<><>]}{{{}[]}})<<<{}()>>>]>([[<[{}<>]
{([{({(<{[<(<(()()){{}()}>[(<><>)<<>[]>])[{{{}()}[(){}]}[<()[]>[{}[])]]>{([{{}{}}{[]}][{{}<>}{<><>}]){[[[]()
[{(([[{([(({(<{}()>({}<>))((()())(<>[]))}{<{{}[]}[{}()]>{{()()})})<{{([]{})[<>[]]}[{<>[]}{
<<([{{({{{[(<[<>()][()<>]>)]}<(<<<<>()><{}()>>><({{}<>}{()[]}){<(){}>}>)>>})<[{[<([[{}{}]{{}()}]
<[{{[<[{(<<([([]{})]<[[]{}]{<>()}>)(<<<>{}>{{}[]]>(<[]()>(()[])))><<[{[][]}{[]}](([])([]))><({{}{}}{[][]})
{{{({{{([<<<{[()]({}{})}((()[])<()<>>)>{{<{}<>><{}()>}}>(<<(())({}())>{{{}}({}())}>{<[{}<>]<{}{}>>[{<>()}
{<({<[{[<<{{[[[][]][<><>]](([]{})<()[]>)}<<((){})><[[][]](<><>)>>}{(<<{}<>><<>>><((){})([]<>)>)<(([]))(
({{{([({<((<<<()>[[]<>]>(<<><>>(()()))>))>})]){({[<[<<[[{}{}]][([]<>)]><{<{}()><()<>>}(<[][]>[{}()])]>{({{
(<{<<[[[(<{<({<>()}{{}<>})<<()()>(<>[])>>(({{}()}([])))}>([[<({}())({}())]((<>{})<<><>>)][[<(
[([({{{[<([<[(<>[])[{}[]]]<[[]{}][<>]>>])<(((<()<>>(<>{}])({<>{}}[{}<>]))<([()()]{[]<>})({<>()}[{}
<(<<([{{[<((({<><>}<<>>)[[[]<>]({}())]){(<<>()>{[]()})[<()>{[][]}]})>]<[[[{(<>{})<(){}>}[{<>{}}]]]][
{[[[{[(((<{[{([]{})[[][]]}(<{}()><<>[]>)][<[<>{}]>]}>({([(()())<[]{}>](([]{})[<>{}])][[{[]{}}<<>{}>]({{}}[<>
{{{([[<[({<<<({}{})<[]()>>[[<>[]>{<>[]}]>[({<>[]}({}<>))[[[]()][()<>]]]>})]>]<(<<<<[<((){})<{}{}>><{()()}((
[{<<<[((<{{{[<{}{}>[{}{}]]([{}<>]{{}<>})}{{[{}{}][{}]}({[]<>}{<><>})}][([<[]<>><{}<>>][<(){}>(()
[{<(<[{(<(<((((){})<[]<>>)[{()<>}{[]<>}])><(((<>)(<>[]))(<[]<>>))([<<><>>[[]<>]]{<[]()>{()[]}})>){<({{[][
<(<<<[([[<{{(({}[])[<>{}])<(()<>)({}{})>}}>{{([(<>())<()[]>]{{[]<>}})<[[<>()]](<()[]>)>}<{[<{}<>><{}[]>](
{((<[<[<(<[({{{}<>}(()<>)}{(<>{})[[]{}]})(((()[])))]>)[{([([<><>][{}[]])[<()[]>(<>[])]]({[
[({([<([({<(<<(){}><{}<>>>{{<>[]}[()[]]})[[[{}[]](()())]]]({[{(){}}{()}]<{{}()}{{}()}>}[([[][]][()[
({[[{[[({{[[(<<><>>{()}){[()()]}]<{{<><>}({}())}{{[][]}{()()>}>]<[{<<>[]>[[]<>]}]<[<()[]><(
(<[{[(<{(<{{[{<><>}{[][]}](<(){}><[]()>)}}><{<(<<>()>([]<>))<({}<>){{}()}>>}{([(()[]}[<>[]]])<{{[]{}}
<{{(<([(<<<<[{{}<>}(()[])][<{}[]>[<>[]]]><<{[]()}(()<>)>({()<>}({}[]))>><[(([]{}))[{<><>}([][])]]{{(<>())}(
{<[(<{[[(<<[{<(){}>{<><>}}((()<>){<>()})]<[[{}<>]{{}[]}]{([])([]{})}>><{(<{}[]><()<>>)}<(({}()]{[
[{[([([{{{{([(()[])[()()]])[[(<>{})[{}[]]]]}}}{<({[<()[]><{}()]]}{[[[]()]{()()}]})<<<[{}<>](<>[])>[(()<>)([]
{(<{([<<<((({[{}<>]({}())}))[{{((){})[()()]}<{{}<>}<()[]>>}{{{[]()}}}]){((((()())(())){(<>{}){{
{<<{{{([[<{<<[{}<>][<>[]]>>(([()()](<>[])){([]{})})}>{<((<<>()><[]<>>)({[][]}[[]{}])){(<(){}><{}>)(
[[[{[{{{{[<{((<>())((){}))(([]{}){()()})}>([[[{}{}]{[]()}]{(()())<{}[]>}][{((){})<{}[]>}<<[]><
(<[[<[{[<(<[<<{}[]>[[]<>]>((()<>)[<>[]])]{[[{}<>]({}{})](<[][]><[]{}>)}>([{(<>[])<{}{}>}({(){}}[()<>])]
{{<[{({([[(([[{}<>][{}<>]][[<><>]]))<([({}()){[]()}](({}())<{}<>>))>]<{<(({}{})[[]<>])[<{}{
[[({(<[<<{<{<({}())(()[])><((){})[()<>]>}{{<()>(<>[])}}><[([[][]]<()<>>)][<(<>())[()()]>{(<>())}]>)>((<<[
[([{<<[(([((<<()[]><{}[]>>[{<>()}<()[])]){[{()[]}{<>[]}]{{<>}(()())}})<[(({}{})(()[]))(<[]
((<<{{{<<[{[<<[][]>[<><>]>(({}<>)(<><>))](<<[]<>>(<>[])>[<<>{}>((){})])}]>>(({{([<<><>>{{}
([<(([[[((<(([<>()]<()<>>)<[[]()][{}()]>){<(()<>){()()}>}>{(<(()()){{}<>}><<[]<>>[(){}]>)[<<{}{}>{[]
({[<<[{<{<<<[<{}[]>]{[[][]]{[]()}}][{<<><>>(()())}({{}[]}<{}[]>)]>>((([<{}{}>({}())]({{}()
{{[<<<[{(([<[<(){}><<>[]>]({<>[]}[<>{}])>]([<[[][]][[]{}]>({[]<>}[()<>])]))(([({{}()}{<><>})[[()()](<>[]
[([{(<[<([[(<(()[]){(){}}>)[[<[]()>([]())]({[]<>}<{}()>)]]([<{[][]}(()<>)><[{}[]][()[]]>]<[<{
(<[([<<<(<[({(())(()[])}<{<>()}{{}()}>)[[{()[]}<<>[]}]{[<>()][{}{}]}]]>{{[({<>[]})][([[]()]<{}<
[[[<<{({[{{<[[[]()]<(){}>]{([])<()[]>}>[[({}[])[[]<>]][<(){}>[()<>>]]}{<(<[]()>{{}<>})<(<>[])({}
<{[[<[[{[[(<<{(){}}({}<>)>({{}()}([][]))}([<[]{}>(<><>)]))<{{<[]<>>(()<>)}([[]()]({}[]))}({[<>{}
(<[<[{{([{(<[[()()]]{{<>()}{<><>}}>(<[()[]]{[][]]>({<><>}<<>[]>)))((<<()[]>>)[[<{}[]>]<[{}()]<{}<>>>])}[
{{{[<{[((<([<{(){}}{{}[]}>{[(){}][{}{}]}])<<[<<>[])(()())][((){})]>{({()[]}[[]{}])}>>){[({
{(((<(<{(<<((<[]()>))({({}<>)({}<>)})>>)}>)><[[<[<[[{(<><>)({}())}(({}<>){()[]})]]{{[{<>{}}
{{(<<(<([({(({[]{}}{{}[]})<(()())[()()]>)}<{{[{}<>](<>{})}{{{}()}{<>{}}})(({{}{}})(<[][]>{{}()}))>){[<[{<>()}
[(<{<([[[<({[{<><>}{<>{}}][{()<>}{<>()}]}<(<()[]><()<>>)>)><<([[{}{}]]([<>[]][[]<>]))(<<<>()>[()<>]>
({<{(<{[(<<(<([][])[(){}]>{({}<>)[{}[]]}){(({}[])[()()))(<[][]>(()<>))}>>)((<(<({}[]){[]()}>){({<>()}[{}
{<[([<<[(<{((<{}<>>)(<{}[]>{{}[]}))}(<[<[]()>([]())]{[{}]<<>[]>}><[{{}<>}[{}[]]](([]<>)<{}{}>)>)>){
[(({<([(<<[<<[[]<>]<()()>>{({})([]{})}>]<[{[<>()]{[]<>}}{{{}<>}<<>()>}]>>>((<{(<<><>>{[]{}})({<>[]}((){
{[[([[{<<[[[<[<>{}]{<>()}>({{}()}[()<>])]]({{<{}[]><<><>>}{<()<>>}}{{{[]()}<()<>>}<(<>[])(()[])>}
{<{<{{{{[[[((<{}{}>{{}{}})<{{}{}}{(){}}>)[[(()<>)]]]({{([]())[<>[]]}}[{<[]<>>((){})}([[]<>])])]
<[({({[[<(<({([]<>)[<>]}[[()[]]([])])<(<(){}>(()[]))[<<>()>[[]{}]]>>>><{[{<[{}{}][{}()]>{([]())[<><>]}}<{<<
[{<([<[(<({[<[<>]<{}[]>>{({}<>)[[]<>]}]{{{[]<>}(()[])}<(())>}}[({{[]()}{{}{}}}{{[]{}}[()[]]})])<{({{(){}}
{{([(([{{{((<[()[]][<>{}]>[<<>()>[[][]]])<{<{}>[(){}]}{({}())[()()]}>)({({<>[]}<[]()})<({}{})<<
(<(<{([<((<{<<{}<>>[()()]>({[]<>})}([[<>()]([]())])>{([{{}[]}(<>[])]{[[][]]{[][]}})}))>(<[{
[({{{(<[{{{<(<{}>)<{<>()}<(){}>>>[[{()()}(()<>)][[[][]]([][])]]}}}((({((<>{}){{}{}))[{{}<>
[<(([(<[{[<<({(){}})([<>[]){[]()})>>([[<()[]><{}>]])]<({[{()<>}<[]<>>][[<>()]]})>}]>)]{<{<(
([(({({{{[[{(<[][]><{}<>>)}[((<><>)(()<>))<{<><>}{<><>}>]]{(([{}<>][[]()])<<[][]>([]())>){<[(){}]>}}][(<<
({(<{<({{{<(<<[][]}>[{[]<>}{[]{}}])><(<(<>[])([][])>{({}<>)}){{<[]()>(()<>)}}>}(<<<<{}{}>[(){}]>[[()[]](
<[<((<{{{<<{({<>[]}){<[][]><[]<>>}}{[{[]()}[{}[]]][({}())]}>[{<[()<>]>[{()[]}((){})]}(({[]()}
[<({{[([([<{<[[]]<{}{}>>{([][])[()<>]]}[[<(){}><(){}>]]>((((<>{})[<>{}]){(()[])}){<[<>](()<>)>([[]<
<[[([[[(({{<(({}){[][]})[[<>[]]([]())]><[<{}{}><{}()>]>}<(<{<><>}{()[]}>([{}()]((){})))>}{{([{{}}{<>[
([[{<<<<(({(<([]{})<{}[]>>)}([[<{}()>)([[]{}]<<>()>)]{{{(){}}}[<()<>>{<><>}]}))<[{{<()()><{}{}>}}][{{<(){}><
{[{{(<{{{<([[{{}()}{{}{}}]]({<[][]>(<>[])}[[[][]]{<>[]}]))>}}}>)}}{<[<{[{[<[({[]}<[]{}>){(<>{})(<><>)
<{{([<{{{{<{{{()[]}{[]()}}{(())((){})}}{{(()[])[{}<>]}(<()<>>([][]))}>}}<[{({<()[]>({}[])}
{(<([(([{{{({[()()]<()>}[([]()}<<><>>])[{[<>[]]<<>>}{{[]<>}(<>())}]}}<{{[[{}[]]]}(<<<>()>>({[]()}<<>[]>)
<[{{{[{(<<(({<<>[]>{[]}}<{{}[]}<{}[]>>)[[([]())(<><>)][[[]()]([]{})]])[<{(()[])<()>}>([{{}{}}]{<(){}>(()())
[(<[({<{[[{<{[{}[]]{[]<>}}[<()<>>[[][]]]>(<[{}<>]({}())><[{}{}]{()()}>)}((<<<>[]>(<>{})>[(<>())[{}{
[[<{{<<[<<<<({{}<>}<{}[]>)((()[])[[]<>])><([<>[]]([]<>)){(<><>)}>>[({{()}{<>[]}}[([][])[{}[]]]){([{}()][<>{
{{{<({[([({<[[{}<>](()())]([<><>]({}[]))>}(({<<>()>[[]]}[<()>{<>{}}])))]<{({{(()())<<>>}}[({[]{}}[
(<<{(({{(<{{[<{}{}><<>()>]{{()[]}<<>{}>}}(<<{}<>><()>>{<()<>>([]{})})}<[{([]<>)<<>[]>}[<{}()><{}>]]>>
{<[[<{[{(<{<<(<>)<{}{}>>>[<<{}()>({}{})>]}<<[({}[]](()[])]{<[]<>>(())}>{<{()<>}({}<>)>{<()
[{((<<{<{[{[([()<>](()())){(<>())}}([[()<>][{}()]][({}[]){[]()}])}([<[()<>]([][])>[[[]{}]{()[
[<[<[<<[([<{[{()<>}({}())]<{{}<>}([]())>}(<<<>{}>[{}{}]>[[[]()]])>]<({({(){}}<[]{}>)([()<>](()))}[({[
[<[<[(((<(({{([][])}}<[[[][]]{(){}}>(<()[]>[[][]])>){([(()<>)<()()>]<[{}()]([]())>)<<{<>()}>([<>[]]{[]
{{<{<[{[{[(<([{}()]{[]<>})({<>})>(({{}{}}([]{}))))<[[({}{})<()[]>][{[]{}}{(){}}]]{([()<>])(<()[]><<>()>)}>]}
((({([{(<{<[[{{}<>}<{}()>]{([]<>)[{}[]]}]>(<([[]<>])((<>[]))>{<{[][]}(<>())>{{{}()}(()[])}})}>{[
<{(([(<<<(<({{[]<>}{<>[]}}{[[]{}][[]{}]})>[<<[{}<>](()<>)><(()<>)[{}()]>>(<{<>[]]({}[])>{(<>)<[]{}>})]){[<<[(
<{<{{<<<{((<([()()])(<(){}>{<>()})>)<([([]()){{}[]}]{{{}}<{}[]>})(<{()<>)>[<{}()>])>)(<(([()()](
(<[{(<(<[<<[((<>[]){<>[]})<(<>[]]({}{})>][[{[]{}}{()[]}]]>>[<{(<[][]>{{}{}})}<([()[]]<[]<>>)[{<><>}<{}{
({{<<({<<[<[<(<><>)<()<>>><[()<>]([][])>]>[{{<()<>><()<>>}}(<{{}()}><{{}{}}<{}{}>>)]]([[[{[
([[<<([[<([{([()[]](<>[]))<<<>[])({}[])>}[{[[][]]}]])[<[[({}{})<{}<>>]]([{{}<>}({}[])](([]())({}{})))>[[
<{<(<{({[({[[[()[]]{{}[]}][[<>[]>{<>[]}]]})]<{[{<[{}[]]{<>()}><([]<>){<>{}}>}{(<(){}>{<>{}})
<<<[<{(<{(({({<><>}{{}<>}){([][])([][])}}[<{(){}}<<>{}>>{([]<>)[()[]]}>)<{{{<><>}{<>{}}}{(
<[<<(({<<[<([<{}()><<><>]])<[[{}<>][<>{}]]<[{}<>](<>{})>>>](<(<[[]<>][(){}]>(<<>()>{<>})){[({}[]
<[[{<[([[[[{([()<>])<[[][]]{[]{}}>}](<[(<><>)]>({{(){}}<[]()>}))]]]{<({{(<<>()><(){}>){<[]<>>}}}[[
<{[[[(({{[{(([{}()][<>()]))[([[]{}]<{}[]>)([<>[]]{{}{}})]}[{[(()[])]((<>{}){()()})}<<{(){}}[[]<>
(<((<[[{((({((()<>)){{{}<>}(<><>)}}<((()[]))>)([{(<>[])([]<>)}[([][])(<>[])]]<<<<>{}>>[([][])[{}<>]>>))([<
[(((<[<{[([{(<<>[]>((){}))[[[]()][<>{}]])]<({<{}>{[][]}}{{{}<>}[<>[]]})<<{{}()}{(){}}>({<>{}}{{}[]
{((<[{[<<<[{<[(){}]({}{})>}<[<[]{}>({}<>)][{(){}}<<>{}>)>][<[[{}]({}[])]>]><[{{{{}[]}}({[]{}}(<>
[[<[(((({[[[({<>{}}{{}()})[<(){}>{<>}]]{(<<>{}>(()<>))([[]<>]<()<>>)}](<([[]{}]<()()>)>{<[()
[<<<[{[<{[(({([][]){<>}}))(<{([]())[{}()]}[[{}[]]{[]<>}]><{(<>())<[][]>}[([][]){{}()}]>)](
<(<{<<[([[<{[[<>()]<{}{}>][[(){}]<<><>>]}>]{(([[<>[]](<>{})>{<()[]><[][]>})[<[(){}]{[][]}><[<>()]([][]
<[([<<[{{[<<<{<>()}[<>()]>[<{}{}>[{}{}]]>[{[(){}]}([[]{}])]>]}}]>>{<([<(({({[][]}){([]()){{}{}}}}
[({{{((<{<{[<<{}{}>><<[]{}><<>{}>>][<{{}()}>]}[(<[[]]<<>[]>>[([]())<<>{}>]){<[{}[]]>((()<>)[[]{}
{[<[[(({([[<[(<>{})<<>{}>]{<()<>><{}[]>}>[[{{}<>}([]<>)][({}())([]())]]]])[[({{[[]<>][<>{}]}[[<>
(((<[[<<{{[[[([]{})<{}<>>]]{{[<>[]]<{}{}>}({<><>}{()()})}][[<<[]()>{<>[]}><(()())<()[]>>]{{([](
[<{<[[[<<{[{<({})([][])>[{[]()}]}<[{{}()}[<><>]]>][((<[]{}><{}()>)(<<>()>))([<<>()>((){})>)]}{[({(<>())<(
{([<[{{{<[{[({<>()}(<>{})}[{()()}[<><>]]]}<{{{<>[]}[{}[]]}({[]()}[{}()])}<({()()}<<><>>){{{}{}}
{{<[[<({([{(([[]<>][{}<>])){{({}{})<<>()>}}}[[{[<><>][{}{}]}<{[][]}([]())>]<<[()[]]{()<>}>{<{}[]}(()())}>]
<({<[([{[[<{<{[]{}}[<>]>}>([(<()[]>[[]<>])<{<>[]}>]{[(()())[{}]][<{}<>><{}>]})]]([{{{([]{})[(){}]}[<
[<<[{[{{[[{[[[()<>][()[]]](({}<>)[()<>])]<<(()[])>([<>[]]{()<>})>}([<[{}{}]>{({}<>){[][]}}][{[<>[]][<>]}])]]}

10
aoc2021/input/test10.in Normal file
View File

@ -0,0 +1,10 @@
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
(((({<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]