Added Day 10 and 11 with test cases
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e381eb3d37
commit
78ab98234c
@ -18,6 +18,18 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Input\Day10_input.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Input\Day10_test.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Input\Day11_input.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Input\Day11_test.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Input\Day1_input.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
@ -89,6 +89,22 @@ namespace AOC2021.Tests
|
||||
Assert.IsTrue(request.Answer.Equals(result.Answer));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Day10()
|
||||
{
|
||||
var request = new TestRequest() { Day = "day10", Answer = new Answer() { Day_A_Test = "26397", Day_A_Input = "168417", Day_B_Test = "288957", Day_B_Input = "2802519786" } };
|
||||
var result = _tester.Test(request);
|
||||
Assert.IsTrue(request.Answer.Equals(result.Answer));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Day11()
|
||||
{
|
||||
var request = new TestRequest() { Day = "day11", Answer = new Answer() { Day_A_Test = "1656", Day_A_Input = "1793", Day_B_Test = "195", Day_B_Input = "247" } };
|
||||
var result = _tester.Test(request);
|
||||
Assert.IsTrue(request.Answer.Equals(result.Answer));
|
||||
}
|
||||
|
||||
//[TestMethod]
|
||||
public void MapVsEnumberable()
|
||||
{
|
||||
|
94
AOC2021.Test/Input/Day10_input.txt
Normal file
94
AOC2021.Test/Input/Day10_input.txt
Normal file
@ -0,0 +1,94 @@
|
||||
(<[<[((<[<([<<[]()>{{}()}>({<>[]}<[][]>)])<<[{{}[]}[{}<>]]([()<>][()()])>>>]((<{{([]{})<[]<>>}(<[
|
||||
<[{({[[<{[{{{<<><>><{}>}<([]()){()[]}>}({(()()){{}<>}})}{([<()()>[<><>]><<{}[]>({}<>)>)}]{{[((<>()){<>[]
|
||||
[[{[[(<((<[<<{{}()}<()[]>>(<<>{}>{{}()})>]<<[[{}()](()<>)][<<>{}><[]()>]>{((<>()){{}()))}>>[{[<[<>{}
|
||||
{{((({({(<[({<<>()>([]<>)}({()[]}(<>{}))}[({{}{}}([]()))<({}[])[[]()]>]](<{([]<>)(<><>)}{[[]]
|
||||
[[({[{(((<(<{({}[])}((()<>)([]<>))>({{[]<>}{{}[]}}{[<>[]][()()]})){(<{{}[]}{{}[]}><([][])[<>{}]>)}><<{{{()}[
|
||||
(<{([{<[([(<({{}{}}{<>()})[<{}<>>{()()}]><((<>}(()<>))>){<[[()[]](()[])]>[{<{}[]>(<>())}]}](<[({(
|
||||
<{{{<({[{<<[<({}()){[][]}>[<{}{}>[{}<>]]][[(()<>)([][])]]>><{<[(<><>)]>{(<()[]><[]{}>)<<<><>>(<>[]
|
||||
({{{{<<[{([(({{}{}})<[[]<>]>)])}]>>}[(<[<<<{[{{}()}]<[{}{}]>}>>{(({(<>())<()()>}(<[][]>{()()})))}){[<<([()
|
||||
<(([{(<{{{{([({}{})(<>[])][[()[]][<>{}]])<[<()[]>]}}{<<{{}<>}><{<>}([][])>>{<{{}{}}<{}<>>><((){})
|
||||
<(<<[([<[<({{{<>[]}<()[]>}}[([()<>]([]()))(({}<>){[]{}})])>]{({[([<>()])]})}]{[[<(<{()<>}[{}<>]>{[()[]][<><>]
|
||||
{[[[((<(<[<(<[()()]>)<<<{}<>><<>[]>>(<(){}>)>>](<([<(){}><[]()>](([])))[<{{}{}}{<><>}>{<<>>{<>
|
||||
[<{([{<[<<<[({[][]}<{}[]>){(()<>)<{}<>>}]><{{{[]<>}<()<>>}[(()[])[{}<>]]}(({<>[]}<{}()>)(<{}[]>([]{}))
|
||||
{<[<[<<[<[{[{(()<>)}(<<>{}>[<>()])](([<>[]](<>[]))[[[]<>]([]<>)])}]><{{<{{[]<>}{{}[]]}<[<><>
|
||||
[((<<{<[{<{(<[[]{}]>)}<<({()[]}[[]])<(()<>)[(){}]>>(<[{}<>]{<>[]}>)>>{[<<{()<>}]<[[]<>]({}{})>>[<[(
|
||||
<<<<{[<(<[[<<{()[]}({}<>)>{{[]<>}{[]()}}>](([{()}]([(){}][<>[]])))]{[(<(()[])[<>[]]>{([]())}){(
|
||||
({<[({([{[(<[{<>{}}(<>[])][<()()><()<>>]>)]}({<<<{[]{}}[<><>]>>><{((<><>))<<<>[]>{<>[]}}}([(()<>)<<>{
|
||||
<(<({{[<[{<[[{()[]}]((<>()))]<[[()[]](<><>)][[{}{}]<()>]>>}]>]{<(({<((())[<>{}])[<[]<>>{<>{}}]>}<<{[<>[]]
|
||||
{[([{((<({<{[{[][]}<[]{}>]{{<>{}}<{}[]>}}>[<{(<>[]){[]{}}}<{[][]}{{}}>>]}{((<[[]()]<[]>>)[[<()[]>
|
||||
(<{(({[(<{{(({<>[]}[{}])[[()()][[]()]])}[{(<()()>{[]<>})(<(){}><[]()})}[(([]{})<<><>>)<(<>())<<>
|
||||
<(<{<({<((<{(({}{})><(<>[])>}>[<{<<>{}>([]{})}{[<>{}]([]())}>([[()[]]<{}<>>]({[][]}<()[]>))]){<[(<{}<>
|
||||
([{({([({([[[{[]{}}({}<>)]]((<{}()><<>{}>){({}[])<{}<>>})]>}{[({{(()<>){<>[]}}[<()[]>[()<>]]}<<<<
|
||||
{(<<[{(<<<(<<{[]<>}<[]()>><(<>)(()[])>><{(()<>){{}<>}}>)({{(<>())[<>[]]}}<[[{}{}](()())]<{{}()}(
|
||||
<<(<<{[{([{([[<>()][[]()]](<()<>>[[][]])))<(<<[]<>>>)[({<>[]})]>][<<<(<><>)(<>)>[([]{})]>>])[[{(<(<>()){[]
|
||||
<<<{[(<(<[(([{{}}]((<><>)[{}<>])))<({{<>{}}[{}<>]})>]{<[<(<><>)[{}{}]>[[{}[]]({}{})]]{<[[]<>
|
||||
<{(({{{[[[<([{{}[]}]({(){}}((){})))>]]<(({[{<>()}({}{})]})(((<(){}>[(){}])[{[]{}}(<><>)]))
|
||||
<[[{((<{([(<<{()<>}(()[])><<[][]>>>{(<{}[]>({}<>))})<<<<()()>{[]()}>(<<>()>)>>])}>))}[<<{[<{{{{<[]<>>
|
||||
({(<{<(([[({{{[]{}}[()<>])}{(((){})<()[]>)})[<([[][]][[]()]){{<>()}[[][]]}>(<(<>)<<>[]>>{[<>[]]{[](
|
||||
((({(<<({<[[[{<>}[<>()]]<<{}<>>({}[])>]]<({<{}{}>[()[]]}{<{}<>>{<>()}}){[(()())<{}[]>][([]{})[[]<>]]}>>[{[<((
|
||||
{[[<[([{{<[<[[<>()][{}[]]]{<<>()>{[]()}}>]{[<[<><>]<<>{}>><{<><>}<<>{}>>)[{<{}<>><<>[]>}{{<><>}}]}>{
|
||||
<(<{(({([<[([([][])(()<>)]{[<><>](()<>)})((([]{})[[]()]))]([({[]()}{<>{}}){{{}})])>]{<<({<<>[]
|
||||
<<{([{<[{{(({{{}()}{[][]}}<{[]()}{<><>}>){{<()[])<<><>>}[<{}[]><{}[]>]}){<<{[]()}<<><>>>{<{}{}>({}(
|
||||
<[[<<(<({<([((()<>){()[]})[([][])<{}[]>]]({<<>()>((){})}([[]()]({}<>})))>})[<<{({([]())<<>{}>}{{()
|
||||
<{(<[[<(<<({(<[][]><<>{}>)[<{}{}>[()<>]]}(({()[]}<{}[]>)))>[<[{(<>{}){()<>]}<[{}[]][<><>]>]>]>[<[({<
|
||||
(<(([{{[<(<[<{()}{[][]}>]>{(((<>())[{}{}])<[[]]<(){}>))})>](<[(<(<[][]><<>()>){<{}[]>([]{})}>{(([]))<([]<>)[(
|
||||
{((<{(({({<[{<{}<>><<>[]>}((<>{})[[][]]]]{([()[]](()()))([[]<>]{{}()})}>})(<[<<<[]{}><()[]>><<{}<>><<
|
||||
{<{(<[<{[[{{{[{}()]}({()()})}((([]<>){()<>})(<<><>>))}<[{{()()}{[]()}}]>]<[((<[]()>((){}))([()()][<>
|
||||
([({((([<({[[[[]()](()<>)][({}())<<><>>]]}<{<[{}<>][{}{}]>(([]<>){[]()})}[<<[]()>[{}()]>]>)<([([()
|
||||
<<{({<<[{[<{<(<><>)([])>({{}[]}{[][]})}<([()()])(([]{}))>>([(<[][]>{{}<>})[[<>{}]<()<>>}]{[{{}[]}({}<>)]<[[]<
|
||||
([<{[[[([[<[(((){})[{}()]){{[]<>}(()<>}}][({(){}}{<>[]})]>]])({<[{<(()<>)>({[]{}}<{}()>)}(([()()]<<><>>
|
||||
([({{[<([[{<[{()[]}[<>]]({<>()})><{({}[])(()<>)}{(<>{}){{}<>}}>}]])>]<([([[{[[<>{}]{[]{}}]{<[][]]{{}[]}
|
||||
[[{(({[{{[[[<(()[])[[]<>]>]{<{()[]}{()()}>{(<>[])({}[])}}](<((<><>)[<><>])([<><>])))][[[(<(
|
||||
[{(<<{(((([[<<{}<>>({}())><<<>[]>[{}{}]>][<(<>[])<{}>>[<[][]>{{}[]}]]]<<(<[][]>{[]()})({{}()}<{}<>>)><([<
|
||||
{<[[<{{<[[(<{{()()}<[]<>>}><<{<>}<{}{}>><<[][]>>>)<{{[()<>]{{}{}}}<({}[])[(){}]>}>]]>}<<(({{(((){}
|
||||
((<([[<{{<(<([<>()]{(){}}]({[]()}<()()>)>(([{}[]]((){}))))<[{[<>{}]({}<>)}]>>}[[<({(<>())(<><>)}){([<><>][[][
|
||||
<[([<(({<(([<({}<>)[()]><<[][]><<>()>>]<{([]{})}<{<>{}}{[]()}>>)){[[{[<>{}][[][]]}]<[[<>()][{}[]]]>][<[[()
|
||||
((({({[[[[{{<(<><>)((){})>}}]{{[[[<>[]][<>[]]]{{()<>}[[][]]}]{{{{}{}}{<>[]}}([{}][<><>])}}({(
|
||||
<<<{[<(<({[{[({}[]){()()}]}]}{[(({{}()}[[]<>])[([]<>)(<>)])]{{({()<>}{<><>})<<{}()>>}<[<[]{}>]{([]<
|
||||
(({[(<<<<{((((<>{}){[]<>})[{[]<>}])(([[][]]<()<>>)<[{}<>]<[]{}>>)){(({()[]}<[][]>)[[<>[]]{()<>}])([[()[]]]<
|
||||
<([<<[<<[{[[<<[][]>>{((){})[<>[]]}]((<{}{}>[[]<>]){<{}()>(()<>]})]({[(<>{})(<><>)](<(){}>[
|
||||
((<{[{[[{<<((<<>{}>{<>()}){{[]()}((){})})((([]<>)<<>[]>)<(()){<>[]}>}><[<(<>[])<{}()>>]{<<
|
||||
[(<[{([{<{([[(()){(){}>]{{{}<>}<[]()>}][(<()<>>[(){}])<[()](()<>)>])}({([[[]{}]({}())]({()<>}{
|
||||
[<[{[<[{[[<[{([]){{}{}}}]>][[<<(<>{})<<>{}]><{{}()}>>(([{}<>]({}))[(<>{})<[][]>])]]]}]<[(({
|
||||
(([{{<<{<[[(((<>())<[]{}>)([()()}(()())))[((<>()))<[{}()]({}[])>]](<{{<>}{{}<>}}>)]>[{<{{[
|
||||
<<[[{<([<<<<{({}<>]([]())}({{}()}<()<>>)>[<<()()>{()()}>({()<>}[{}()])]>{<(<[][]>)>[<[{}{}]>((<>()
|
||||
(<{[<[({{[[([<[]{}>[[]()]]{{{}[]}(<><>)})]<[([<>{}]<{}[]>)[<{}<>>{[]()}]]<(<<><>>(()()))<[<><>}{{}{}}>>>](
|
||||
[<((<{{[(<(((<[]()>([][]))(<()<>>{{}[]}))((<{}{}><{}[]>)({{}[]}[[]{}])))<{(<[][]>)<{<>()}>}{{[()<>]}{{<>(
|
||||
{((([{{((<<<<[()()][(){}]>{[[][]](()<>)}>>{{{{<><>}[[]<>]}[{<><>}({}()]]}([[<>]{(){}}][[(){}](()<>)])}>[([([[
|
||||
[(({<<{([{(<[<()[]><[]()>]((<>[])[<>()])>([<(){}><<>()>]{[<>()][(){}]}))}[<[{[{}()]{()()}}(<<>>{[]})]{[<<>()>
|
||||
<[{[<<({<<<[((<>()){()()})[(<>[])([]{})]]><[<([][])([]<>)>(<[]{}>(()()))][{[()[]]{[]<>}}[(<>{})<<>
|
||||
((<[<[(({[{[[<<>[]]{[]()}]({()<>})]{[<<>()><{}()>]}}(<(([]{}){(){}})>{<{{}()}(()())>})]}([(<{[[][]
|
||||
{(((((<({[<[{<<><>>{<>[]}}(<(){}><[]()>)]<{<{}()>(<>())}[[[]<>]{{}<>}]>>{[{<()()>[[]()]}[<{}>]]}]{
|
||||
(({([{<([<{{<<[]{}>[[]{}]>({{}{}}({}<>))}<[{<>{}}{()<>}][<<>{}>]>}>{({(<(){}>[{}()])[{()<>}[()<>]]}<[{[
|
||||
[[{{[<<[<((<{{{}()}<[]>}{[{}<>]<()[]>}>({[[]{}]}[([]())<[]{}>])){(<<()()>>{[{}[]]<{}{}>})})>]>>]<([<[<
|
||||
{({{{{[[<{<[{[{}<>]}([[]{}][{}<>])][((()()){[]()}){[<>()](<>())}]>}>[{<[{{<>{}}({}())}[<<>{}>((
|
||||
({[((<{{<<<({[{}{}][(){}]})((<[]><()()>)<{<>()}[[]<>]>)>(({<{}[]>([][])}(({}{})<<>()>))<{<[
|
||||
[<<[<{[[{{(<{[[]<>)({}[])}>)}}(({{((<>[])<<><>>)}{[[[]<>]]{{[][]}<{}{}>}}}){[[((<><>)[{}<>])
|
||||
(({<(<([({<(<<()<>>([]<>)>[([]()><()[]>])<[<()[]>[()()]]{[[][]]{{}[]}}>>{{<<[][]><[]{}>>{[{}[]]<<>>}}{{<[]{
|
||||
([{{({({{{<([({}[])[()<>]][[[]{}]([]())])>([[[()()][<>()]]([{}[]]{{}()})]<{{[]<>}({}[])}{<()[
|
||||
(<{(({(<{{[<[[()<>]{<>()}][<(){}><()<>>]>{<<<>[]>[<><>]><({}<>>>}](<<{<>[]}[[]<>]>[[[]<>](()[])]>{{{[]
|
||||
[[[<[([([(({{<<><>>([][])}})[([[{}()]<<><>>])<({{}<>})<{{}}({}{})>>])])<([((<[[]<>]{(){}}>{[[]<>]<[]<>>})(
|
||||
(({(<({[[<{<([{}<>]{<>()})([()()](()<>))>(((()())[{}()])({()[]}{{}<>}))}>([({<(){}>([]<>)}{[<>()]<<>>}
|
||||
({{[<<{<<[<<{[()()]<<>[]>}({[]}<<>{}>)>[<<{}{}>[<>[]]><({}<>)<[]()>>]>({(<()[]>(<>[]))}[([()()][{}]){{()()}{
|
||||
(<({{([{<[{(([()]<<><>>))}<<<[()][{}{}]><([][])(()())>>[[<<>[]><[]>]{[<>{}]<[][]>}]>](<(<<[]>({}())
|
||||
(<{<([[[<<((([<>{}]{()[]})([(){}]{{}<>}))[[[{}<>](()[])][[<>[]](<>())]])>>([{([{<><>}<{}[]>]
|
||||
<{[{[{<{{({<<({}[])><{()()]<[]<>>>><[({}[])[()()]]<[{}<>]{<>{}}>>}((({()[]}{[]<>}){[[]()]([]<>)})))
|
||||
[(([[[[<<<[<{{<><>}{[]()}}[({}[])<(){}>]>(([[][]]([]{}))<{{}}(()<>)>)]({<<[]{}>{[]<>}>{[()<>}{{}}}}{{[(){}]}
|
||||
{(([<{<(<{<{{<()><[]{}>}}({{{}<>}}<{<>[]}<{}<>>>)>[<([{}[]]<()<>>)(<{}{}>{()[]})><<{<>[]}(()[])>>]}(
|
||||
(<((<{[[{({[([()[]]<()<>>)[<<>{}>({}[])]][<[<>[]]><{(){}}>]}[<(({})({}()))(<[]{}>(<><>))>[[([]{})[{}[
|
||||
{({([[[[{<([<{{}<>}[[][]]><<<>[]><<>{}>>]{{<{}<>><[][]>}({[]{}}<{}[]>)})>{{{{[[][]]}}}}}[<[[{[{}[]][()()]
|
||||
[{(<([{{{<{<({{}[]}<()<>>){<<>())[{}[]]}>{{{[][]}}[[(){}]{<>()}]}}([(<<>()><[]()>)]{({[]<>}
|
||||
[<[([{<((({<{{<>{}}}<<(){}><()()>>><({()}[[]{}])(([]())[<>[]])>}))){<[{{{(()[])({}())}{{()()}{{}<>}}}[(<{}
|
||||
<([({({{(({{({<>}(<><>))}{([{}[]]{{}<>})}}[{({[]<>}([]<>))[<[]>([]{})]}({[[]{}]({}())}{<{}<>
|
||||
[{(({(({<[[{<[(){}](<>[])>}[[[<>()]][([][])<<>()>]]](((<<><>>[(){}])([[][]]<{}{}>))[<(<>()){[]{}}>[[()[
|
||||
<<{{<[(([{[{[[<><>][[]()]]<(<>[])[[]<>]>}]<([<()[]>((){})][<{}>(<>())])>}][{(<([()()][<><>])(({
|
||||
({(<({([(<[<{[{}()]({}{})}<<{}{}>(()<>)>>]>{([<[<><>]<(){}>><({}[])((){})>]{{<[]()>[{}[]]}(({}{})<
|
||||
<[{<{((<{((<[([]<>)]<{{}()}{()[]}>>(((())){<[]{}>[{}[]]}))<[<<{}[]>((){})>[<()()>{()()}]]<[[(
|
||||
{{{((<(([{({(({}{})({}{}))}[<{()<>}[{}()]><([]()){[][]}}])[([[()[]][[]{}]])<{({}())[<>{}]}{(<>[])}
|
||||
<({[{[[{(({<(<<>>[(){}])({[]{}}<[]()>)>}<{[([]())<<>{})]{(()[])<[]>}}(<[{}{}]>(((){}){{}{}}))>)
|
||||
<{[[({[{[{[([[<>{}]((){})][[[][]]{()<>}])<[<{}()>(<>{})]<<<><>>[<>()]>>][[[<[]<>>{{}<>}]<{[]{}}<[]{}>>]
|
||||
(({(<((({({{<<{}()>(()<>)><<<>{}>[{}{}]>}(((()<>)(()()))(<{}<>>))}[<[[[]<>]]({[][]}[<>{}])>]){[(({{}{}}){([][
|
||||
[{{<({<<{(<({<{}<>>[[]<>]}<[{}[]](()()]>)>([{{<>[]}}{([][])([][])}]))({(<{[]{}}{()<>}>([<>()]{[]{}}))
|
||||
[<({[(<{{{[((<[]<>>(<>[]))([[]<>]<()<>>))(<((){})>)]}}}>{{<([<[<()[]>{{}<>}](([]())[[]<>))>]{(({[][]}<<>(
|
||||
([(({<([{({<(([]<>)(()[])){<()()>{<>()}}><([[][]]<()<>>)[[[][]]<()<>>]>}[{[{()[]}(<>[])]([<>[]]<<>()>)}])
|
||||
{{{([<[([{(<[{[]()}<[]{}>]>)}])<<<<({(<>())<{}()>})[{({}[]}{<>[]}}<<[]<>><{}[]>>]><(<[()<>
|
10
AOC2021.Test/Input/Day10_test.txt
Normal file
10
AOC2021.Test/Input/Day10_test.txt
Normal file
@ -0,0 +1,10 @@
|
||||
[({(<(())[]>[[{[]{<()<>>
|
||||
[(()[<>])]({[<{<<[]>>(
|
||||
{([(<{}[<>[]}>{[]{[(<()>
|
||||
(((({<>}<{<{<>}{[]{[]{}
|
||||
[[<[([]))<([[{}[[()]]]
|
||||
[{[{({}]{}}([{[{{{}}([]
|
||||
{<[[]]>}<{[{[{[]{()[[[]
|
||||
[<(<(<(<{}))><([]([]()
|
||||
<{([([[(<>()){}]>(<<{{
|
||||
<{([{{}}[<[[[<>{}]]]>[]]
|
10
AOC2021.Test/Input/Day11_input.txt
Normal file
10
AOC2021.Test/Input/Day11_input.txt
Normal file
@ -0,0 +1,10 @@
|
||||
6111821767
|
||||
1763611615
|
||||
3512683131
|
||||
8582771473
|
||||
8214813874
|
||||
2325823217
|
||||
2222482823
|
||||
5471356782
|
||||
3738671287
|
||||
8675226574
|
10
AOC2021.Test/Input/Day11_test.txt
Normal file
10
AOC2021.Test/Input/Day11_test.txt
Normal file
@ -0,0 +1,10 @@
|
||||
5483143223
|
||||
2745854711
|
||||
5264556173
|
||||
6141336146
|
||||
6357385478
|
||||
4167524645
|
||||
2176841721
|
||||
6882881134
|
||||
4846848554
|
||||
5283751526
|
@ -28,6 +28,8 @@ namespace AOC2021.Controllers
|
||||
[Route("day7")]
|
||||
[Route("day8")]
|
||||
[Route("day9")]
|
||||
[Route("day10")]
|
||||
[Route("day11")]
|
||||
public AOCResponse Day(AOCVersion version, [FromBody] string input, bool IgnoreLogMessages = false)
|
||||
{
|
||||
AOCRequest request = new AOCRequest() { Input = input, Version = version, IgnoreLogMessages = IgnoreLogMessages };
|
||||
|
70
AOC2021/Days/Day10.cs
Normal file
70
AOC2021/Days/Day10.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using AOC2021.Models;
|
||||
using AOC2021.Models.Day10;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AOC2021.Days
|
||||
{
|
||||
public class Day10 : AOCDay
|
||||
{
|
||||
private List<ChunkReaderResult> _results;
|
||||
public Day10()
|
||||
{
|
||||
_results = new List<ChunkReaderResult>();
|
||||
}
|
||||
protected override AOCResponse ExecutePartA()
|
||||
{
|
||||
foreach (var line in GetSplitInput())
|
||||
{
|
||||
_results.Add(new ChunkReader(line).Process());
|
||||
}
|
||||
var illegalScore = 0;
|
||||
illegalScore += _results.Where(x => x.isCorrupted && x.CorruptedChar == ')').Count() * 3;
|
||||
illegalScore += _results.Where(x => x.isCorrupted && x.CorruptedChar == ']').Count() * 57;
|
||||
illegalScore += _results.Where(x => x.isCorrupted && x.CorruptedChar == '}').Count() * 1197;
|
||||
illegalScore += _results.Where(x => x.isCorrupted && x.CorruptedChar == '>').Count() * 25137;
|
||||
this._response.Answer = illegalScore;
|
||||
return this._response;
|
||||
}
|
||||
|
||||
protected override AOCResponse ExecutePartB()
|
||||
{
|
||||
foreach (var line in GetSplitInput())
|
||||
{
|
||||
_results.Add(new ChunkReader(line).Process());
|
||||
}
|
||||
var incomplete = _results.Where(x => x.isIncomplete);
|
||||
var totalPoints = new List<long>();
|
||||
foreach (var inc in incomplete)
|
||||
{
|
||||
var total = 0L;
|
||||
foreach (var c in inc.CompletionString)
|
||||
{
|
||||
total *= 5;
|
||||
total += GetPointValueForCompletion(c);
|
||||
}
|
||||
totalPoints.Add(total);
|
||||
}
|
||||
this.Answer = totalPoints.OrderBy(x => x).ToArray()[totalPoints.Count / 2];
|
||||
return this._response;
|
||||
}
|
||||
|
||||
private int GetPointValueForCompletion(char c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case ')':
|
||||
return 1;
|
||||
case ']':
|
||||
return 2;
|
||||
case '}':
|
||||
return 3;
|
||||
case '>':
|
||||
return 4;
|
||||
}
|
||||
throw new Exception("Invalid char for Part B: " + c);
|
||||
}
|
||||
}
|
||||
}
|
167
AOC2021/Days/Day11.cs
Normal file
167
AOC2021/Days/Day11.cs
Normal file
@ -0,0 +1,167 @@
|
||||
using AOC2021.Models;
|
||||
using AOC2021.Models.Day11;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AOC2021.Days
|
||||
{
|
||||
public class Day11 : AOCDay
|
||||
{
|
||||
private static readonly int BOARD_SIZE = 10;
|
||||
public Octopus[,] _board;
|
||||
public Day11()
|
||||
{
|
||||
this._board = new Octopus[BOARD_SIZE, BOARD_SIZE];
|
||||
}
|
||||
protected override AOCResponse ExecutePartA()
|
||||
{
|
||||
CreateOctoBoard();
|
||||
int totalFlashes = 0;
|
||||
PrintBoard("0");
|
||||
for (int i = 1; i <= 100; i++)
|
||||
{
|
||||
//Initial energy assumption
|
||||
for (int x = 0; x < BOARD_SIZE; x++)
|
||||
{
|
||||
for (int y = 0; y < BOARD_SIZE; y++)
|
||||
{
|
||||
_board[x, y].IncreaseEnergy(i);
|
||||
}
|
||||
}
|
||||
//Energy propagation with the flash
|
||||
totalFlashes += Propagate(i);
|
||||
PrintBoard(i.ToString());
|
||||
}
|
||||
this.Answer = totalFlashes;
|
||||
return this._response;
|
||||
}
|
||||
|
||||
|
||||
protected override AOCResponse ExecutePartB()
|
||||
{
|
||||
CreateOctoBoard();
|
||||
int totalFlashes = 0;
|
||||
PrintBoard("0");
|
||||
int i = 1;
|
||||
while(true)
|
||||
{
|
||||
if (DidAllFlash())
|
||||
{
|
||||
Log("Found case where all Octopus flashed at " + (i - 1));
|
||||
this.Answer = i - 1;
|
||||
break;
|
||||
}
|
||||
//Initial energy assumption
|
||||
for (int x = 0; x < BOARD_SIZE; x++)
|
||||
{
|
||||
for (int y = 0; y < BOARD_SIZE; y++)
|
||||
{
|
||||
_board[x, y].IncreaseEnergy(i);
|
||||
}
|
||||
}
|
||||
//Energy propagation with the flash
|
||||
totalFlashes += Propagate(i);
|
||||
PrintBoard(i.ToString());
|
||||
i++;
|
||||
}
|
||||
return this._response;
|
||||
}
|
||||
|
||||
|
||||
private int Propagate(int step)
|
||||
{
|
||||
int totalFlashes = 0;
|
||||
while (AnyLeftToFlash(step))
|
||||
{
|
||||
for (int x = 0; x < BOARD_SIZE; x++)
|
||||
{
|
||||
for (int y = 0; y < BOARD_SIZE; y++)
|
||||
{
|
||||
if (_board[x, y].CanFlash(step))
|
||||
{
|
||||
_board[x, y].Flash(step);
|
||||
totalFlashes++;
|
||||
foreach (var t in GetSurroundingCoords(x, y))
|
||||
_board[t.Item1, t.Item2].IncreaseEnergy(step);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalFlashes;
|
||||
}
|
||||
|
||||
public bool AnyLeftToFlash(int step)
|
||||
{
|
||||
bool flash = false;
|
||||
for (int x = 0; x < BOARD_SIZE; x++)
|
||||
{
|
||||
for (int y = 0; y < BOARD_SIZE; y++)
|
||||
{
|
||||
if (_board[x, y].CanFlash(step))
|
||||
{
|
||||
flash = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return flash;
|
||||
}
|
||||
|
||||
private bool DidAllFlash()
|
||||
{
|
||||
for (int x = 0; x < BOARD_SIZE; x++)
|
||||
{
|
||||
for (int y = 0; y < BOARD_SIZE; y++)
|
||||
{
|
||||
if (_board[x,y].EnergyLevel != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void PrintBoard(string s)
|
||||
{
|
||||
Log("Step " + s);
|
||||
for (int i = 0; i < BOARD_SIZE; i++)
|
||||
{
|
||||
string line = "";
|
||||
for (int j = 0; j < BOARD_SIZE; j++)
|
||||
{
|
||||
line += _board[i, j] + " ";
|
||||
}
|
||||
Log(line);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateOctoBoard()
|
||||
{
|
||||
int row = 0;
|
||||
foreach (var line in GetSplitInput())
|
||||
{
|
||||
for (int col = 0; col < line.Length; col++)
|
||||
{
|
||||
_board[row, col] = new Octopus(Convert.ToInt32(line[col].ToString()));
|
||||
}
|
||||
row++;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Tuple<int,int>> GetSurroundingCoords(int x, int y)
|
||||
{
|
||||
var positions = new List<Tuple<int, int>>();
|
||||
for (int i = -1; i <= 1; i++)
|
||||
{
|
||||
for (int j = -1; j <= 1; j++)
|
||||
if ((x + i >= 0 && x + i < BOARD_SIZE)
|
||||
&& (y + j >= 0 && y + j < BOARD_SIZE))
|
||||
positions.Add(Tuple.Create(x + i, y + j));
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ namespace AOC2021.Models
|
||||
protected AOCResponse _response;
|
||||
protected ILogger _logger;
|
||||
private List<string> _debugMessages;
|
||||
|
||||
protected object Answer { set { this._response.Answer = value; } }
|
||||
public AOCDay()
|
||||
{
|
||||
this._response = new AOCResponse()
|
||||
|
88
AOC2021/Models/Day10/ChunkReader.cs
Normal file
88
AOC2021/Models/Day10/ChunkReader.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AOC2021.Models.Day10
|
||||
{
|
||||
public class ChunkReader
|
||||
{
|
||||
private Stack<char> _stack;
|
||||
private string _inputLine;
|
||||
public ChunkReader(string line)
|
||||
{
|
||||
this._inputLine = line;
|
||||
this._stack = new Stack<char>();
|
||||
}
|
||||
|
||||
public ChunkReaderResult Process()
|
||||
{
|
||||
var result = new ChunkReaderResult() { Line = this._inputLine };
|
||||
foreach (char c in this._inputLine)
|
||||
{
|
||||
//Implies its an opening char so we sent to stack
|
||||
if (isOpeningChar(c))
|
||||
{
|
||||
_stack.Push(c);
|
||||
continue;
|
||||
}
|
||||
if (_stack.Peek() == GetCorrespondingChar(c))
|
||||
{
|
||||
_stack.Pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
result.CorruptedChar = c;
|
||||
result.ExpectedChar = GetCorrespondingChar(_stack.Peek());
|
||||
result.isCorrupted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!result.isCorrupted)
|
||||
{
|
||||
if (this._stack.Count == 0)
|
||||
result.isValid = true;
|
||||
else
|
||||
{
|
||||
result.isIncomplete = true;
|
||||
while (_stack.Count() > 0)
|
||||
{
|
||||
result.CompletionString += GetCorrespondingChar(_stack.Pop());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private bool isOpeningChar(char c)
|
||||
{
|
||||
if (c == '(' || c == '[' || c == '{' || c == '<')
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private char GetCorrespondingChar(char c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '(':
|
||||
return ')';
|
||||
case '[':
|
||||
return ']';
|
||||
case '{':
|
||||
return '}';
|
||||
case '<':
|
||||
return '>';
|
||||
case ')':
|
||||
return '(';
|
||||
case ']':
|
||||
return '[';
|
||||
case '}':
|
||||
return '{';
|
||||
case '>':
|
||||
return '<';
|
||||
}
|
||||
throw new Exception("Invalid char given, no corresponing char found for: " + c);
|
||||
}
|
||||
}
|
||||
}
|
14
AOC2021/Models/Day10/ChunkReaderResult.cs
Normal file
14
AOC2021/Models/Day10/ChunkReaderResult.cs
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
namespace AOC2021.Models.Day10
|
||||
{
|
||||
public class ChunkReaderResult
|
||||
{
|
||||
public string Line { get; set; }
|
||||
public bool isValid { get; set; }
|
||||
public bool isIncomplete { get; set; }
|
||||
public string CompletionString { get; set; }
|
||||
public bool isCorrupted { get; set; }
|
||||
public char CorruptedChar { get; set; }
|
||||
public char ExpectedChar { get; set; }
|
||||
}
|
||||
}
|
39
AOC2021/Models/Day11/Octopus.cs
Normal file
39
AOC2021/Models/Day11/Octopus.cs
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
namespace AOC2021.Models.Day11
|
||||
{
|
||||
public class Octopus
|
||||
{
|
||||
public Octopus(int initialEnergy)
|
||||
{
|
||||
this.EnergyLevel = initialEnergy;
|
||||
}
|
||||
public int LastFlashedStep { get; set; }
|
||||
public int EnergyLevel { get; set; }
|
||||
public void IncreaseEnergy(int step)
|
||||
{
|
||||
if (step != LastFlashedStep)
|
||||
EnergyLevel++;
|
||||
}
|
||||
|
||||
public bool CanFlash(int step)
|
||||
{
|
||||
if (EnergyLevel > 9 && step != LastFlashedStep)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Flash(int step)
|
||||
{
|
||||
LastFlashedStep = step;
|
||||
EnergyLevel = 0;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return EnergyLevel.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user