Merge branch 'master' of ssh://git.pzwietering.nl:55555/flip/contests
This commit is contained in:
102
advent_of_code/2021/d10/input.txt
Normal file
102
advent_of_code/2021/d10/input.txt
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
{<{<{[<[{{([{{{}()}<{}()>}<[{}]>]<<{{}<>}([]<>)>[({}<>){()[]}]>)[[([(){}][<><>])<<()>{()()}>]]}}[(<{[(<>
|
||||||
|
[<{{[[(({({<{{<>[]}[[][]]}[{{}()}[[][]]]>}{<[{()<>]<[]()>]{([][]){{}[]}}>})(([<[[]()][()()]><{[]}(<><
|
||||||
|
{{<{[{[{<{[[[[[]()]]<<{}{}}[{}()]>]]}[<<<<[]()><[][]>><<()<>>({}<>)>>{{{{}{}}[{}<>]}[[<><>]<[
|
||||||
|
([{((<{((<[(({{}[]}<()()>)[{{}<>}[()()]})<{{()()}[<><>]}>]>))}({<<[({{[]<>}[<>()]}<((){}){[][]}>)[{[{}[
|
||||||
|
{([<[((<[[<<({[]()}[[]{}]){<{}<>>{()[]}}>[{<{}{}>[(){}]}<({}<>)[[]()]>]>](({{<[]()>(()[])}{<<>()>({
|
||||||
|
[({[([{<<{<<(<()()>)<[()<>]([]{})>>{<({}[]>{[][]}>([()[]]{(){}})}>{{[{()()}{{}<>}]({<>{}}<{}{}>)}[
|
||||||
|
<[({(<([{<<<(([]()){()()})[<{}><<>>]><({{}<>](<><>))([{}[]]{(){}})>>(((<[]<>>({}[]))([<>()](<>
|
||||||
|
<{[[{<<[{(([<([][])<{}<>>>{{<>[]}{()}}]{(<()<>>(()<>)){<{}[]>[[]()]}})<(<({}()){[]{}}>(<[]()>[[]{}])){<(<>
|
||||||
|
[<[[({<<[[<{{(<>())}<<{}[]>{{}<>}>}[(((){})<()[])){<{}()>[<>()]}]>{[([{}[]](<>{}))<{<>()}{[]()}>](({(){}}<{
|
||||||
|
(<([<[<{{<[{[(<>())<()()>](<<>[]>{()()})}<<{[]{}}>[(<><>){<>[]}]>]<(<<[]<>><<>{}>>(([])[<>{}]))>>>({<<
|
||||||
|
(([{(({<{<{(({{}[]}{<>[]}){<()()><<>{}>})[[({}[]){(){}>]]}[[{{<>[]}{()<>}}[{{}}{[][]}]]<<<()()>([][]
|
||||||
|
[<([{{<[[{<([<{}{}>{(){}}]{[[]{}]{<>[]}})([(<>{})[()[]]])><([{<><>}([]{})]({()()}(<>[])))[[[(){}]{<><>}]<<[
|
||||||
|
<((<<<[<<([({{()[]}})[{{<>[]}([]{})}{{[]<>)({}<>)}]][[<{<>}(()())>[[<>()]<{}{}>]][<({}()){<>}>{{()()}{<><>}
|
||||||
|
[{{[{[({([[<({()}((){}))>{([[]<>]<[][]>)}]{({([]<>)<()()>}(<()<>><<>()>)){{<<>{}>{()[]}}[(()())<[
|
||||||
|
(([[<[[{[{[([[{}()]<[]()>){<()<>>{{}<>}})<{[{}[]]{()<>}}{(()){<>[]}}>]({[{()[]}[<>]]}<(<{}
|
||||||
|
[{[[[<(<<([[<{()<>}<(){}>>({{}()}<<>{}>)](<{{}()}><<{}[]}<<>[]>>)]<<({[][]}[()[]])[<{}{}>(<>[])]>>){<{{{()()}
|
||||||
|
(<[<<{[{[[<{<<()()>{<>()}>}>]{[<([<>[]][()[]])<[<>[]]{{}()}>>((<()()>({}<>))<{(){}}{<>{}}>)][<{(<>{}>}{
|
||||||
|
((<[{<<<<([{{(<>())<(){}>}(<{}<>>[<>{}])}({[<>()]{[]<>}})])[{((<{}<>><()<>>)(<[][]>[()]))<({<>[]}
|
||||||
|
([((((([[{(<<<<>()>(<>[])>>[[(<>[])<<>{}>}<[[]{}](()[])>])([[({}<>)<[]()>]<[{}{}]{<>[]}>](<(<>())>{<
|
||||||
|
<<({[{[{((<<({()<>}<[]{}>)({<>[]})><{([]{})}((()[]))>>(({([]<>){{}{}}})<[{{}[]}[(){}]](<()[]><<>{}>)>)
|
||||||
|
{<[(({<[[([((<()<>><<><>>)(({}())<{}()>))<<<()()>{[]}>[{[][]}[{}[]]]>]{({{<>{}}<(){}>}[<()[]>{<>[]}>)(<[<>
|
||||||
|
{{({<[((([([<<[]{}>[()()]>(<[]{}>)]{[{[]()}]<<(){}>[()<>]>})[{{[{}<>]}[[<>{}]{<><>}]}]]((<{{{}[]}}>[[<[]<>
|
||||||
|
<[(<(<[((<{{[<(){}>[[][]]]}}>))]>)([({<(<<{([][])[()[]]}(<{}[]><()<>>)>{[<(){}>([][])]}>{[<<{
|
||||||
|
(<{{<{<<[((<(<{}{}><[]<>>)<<{}{}><(){}>>>([{<><>}[()()]][{<>[]}([]<>)])))<<{{<<><>>}(<[]{}>(
|
||||||
|
[(((({{[[{{([(<>{})<[][]>])([[()()][{}]](<{}<>>{<><>}))}}<[<{[()]<[]()>}{(<>[]){<>()}}>[[(<>[])[(){}]](({}())
|
||||||
|
({{{<{[<{[{<{{{}{}}}[[(){}]{()[]}]>[[<[]<>>{<><>}]([(){}])]}[({{()[]}[{}[]]})[[{<>[]}<{}[]>]]]]}>](({{[[
|
||||||
|
<{<[{{[{<[[({<[]<>>}{{()()}(<>[])})]]>}[{([[[<<>[]><[]{}>][{<><>}]][((()())(()()))([{}()])]
|
||||||
|
<<<[([({{<<{[({}<>)[()[]]]({()[]}({}[]))}{[{<>[]][[]]]}>>}}[[({[({()[]}<()>)]<[[()<>]{()<>}][
|
||||||
|
{[<({{{{<{{{[<()<>>[{}<>]]<[()()]<[][]>>}({<[][]>[()()]}<<[][]><[]()>>)}{([(()<>)<()()>])}>(([<[<
|
||||||
|
[{<{[<<{{[{[([()<>](()[]))]((<{}{}>)(<[]<>>[<><>]))}]}}>><<<({{{[((){})(<><>)]((()<>){[][]})}(<
|
||||||
|
[({(<{<{[<{([{[]()}[()()]])><[<{[]<>}{{}()}><(()())(()<>)>](<[[]{}]>[([]{})<()()>])>>][{([<([]())[[]<>]>
|
||||||
|
{{(<(<{{({((({{}[]}<<>{}>){<{}()>[[][]]})<{{[]()}{()()}}(<{}[]>{()()})>)})}[<<[[{{<>[]}{<>{}}}{{[
|
||||||
|
<<[<{{[<<{({{(<><>)({}())}({{}<>}[<>])}{[(()<>)<(){}>]{<<><>><[][]>}})<({<[]{}>[[][]]}<<<>{}>{()}>)>}>[<
|
||||||
|
<{(<[<(((<({[[{}[]>(<>[])]<{[]<>}>}({(()())<{}{}>}<<<>[]>[<>()]>)){<<<[]{}>{()[]}>([[]{}]([]{}))><<{<>[]}
|
||||||
|
<{{{[(({<{<[<<[]()>({}())>](<((){})[(){}]>(<<>>([]()))))}>([[<[<{}[]><[]()>]{({}[])({}())}>[[({
|
||||||
|
{([{(<{([<{([{[]()}(<>[])]<<{}<>>(<>{})})[{<<>[]>}(<<><>>[<><>])]}[[{([][])({}())}](<(<>{})(<>)>(([]()){{}
|
||||||
|
([<<{[[<((([<{()[]}>]<{[[][]]({}<>)}])<([{()[]}<()()>]{<<><>>[()()]})>))<[<<<([]<>)[()[]]>
|
||||||
|
[[{([{([{[<(<({})[()[]]>[{[]()}[()()]]}[<{{}()}({}[])>(<[]<>>[()[]])]>([((()[])[(){}])]<[{
|
||||||
|
{{[([[(<(([[[{[]{}}[()()]][[[]{}][<>[]]]][{<<>[]>}]][(<<(){}>{{}<>}>)[<[[]{}]{()()}>[((){})
|
||||||
|
[({[[([[(<[{<([]{})(<><>)>}][<[[()()]<(){}>][[(){}][{}]]>([({}<>)[[]<>]]{[()[]]<[]()>})]>[[<(([]())<
|
||||||
|
[<(<[<<{[<{<<[{}()]<<><>>>{[()<>]<[]<>>}><[([]<>)[{}])<{[]()}[<><>]>>}[[<<<>{}><()[]>>(({}[]
|
||||||
|
(({[{{{[<[{[[<()[]>({}{})][(()[])[(){}]]]({{[]()}}[(<>())<<>[]>])}]<([<<<>[]>[()[]]>{[()<>]<<><>>}]([(<
|
||||||
|
({<(({([[<(<({<>()}[()<>])({<><>}<[][]>)>([[<>()]([]())]))>]{{[{{{{}[]}}<[<><>]<<>[]>>}}}[{
|
||||||
|
[(<([({<<(<{<{{}()}{[]()}>(<()()>{{}{}})}{{([]{})<[]>}<(<><>)>}>[<{<[]>([]<>)}({<><>}{[]{}}
|
||||||
|
<{<[[((([{<[({{}[]}[<>()])(<{}[]>(<>{}))][{{()[]}([][])}({[]})]>({<[()[]]<{}{}>>{<[]{}>{()[]}}}([[{}][{}
|
||||||
|
[([[<(<[((<[({{}{}}[{}[]]){[[]()](<>())}]>){[({[()()]([]<>)}<<<>{}>(<>()>>)]{{((<>())[{}()])[[()<>]<[]
|
||||||
|
{{[<{([<[(<([(<>())<<>{}>])[{[()[]][<>{}]}([[]()]<{}<>>)]>)]<[{[{(())(<>{})}[({}{}){[]()}]]}<<{([]{})}[<
|
||||||
|
([{{<<<([<((({{}{}}((){})){[<><>][[]<>]})<[{[][]}[()()]]([[]<>]{[]()})>)[[<([][]){<><>}>][<
|
||||||
|
((<(<[([<<<({[<>[]][{}<>]}<{[]()}{{}{}}>)[({{}{}}([]()))(<()><<>>)}>(([<(){}>((){})]){<<<>[]>[{}{}]>({(){}}<
|
||||||
|
(<<{{[[[<({({[{}{}]((){})}({<><>}({}<>)))}[(<[{}[]][()<>]>{({}{})(()())})<<[[]{}](<>)>([(){}][<><>])>])[
|
||||||
|
<({{<<(({<[((<{}()>{<>{}}){{{}<>}{<>{}}}){({[]()}<{}[]>)<{()[]}[{}()]>}]{{[{()<>}(<><>)][<<>
|
||||||
|
<[{[[(<<{{(({{{}<>}{<>()}}(<[]{}>))]([[[<>{}](<>)]{(()())<(){}>}][(({}()){<>()})[(()())[{}{}]]])}<<{{<()()
|
||||||
|
[{{([<<{[{<([(())]<<{}>[[]<>]>){([()()]){(<>[]]([][])}}>{<[([]{})]{{{}}((){})}><{[<>[]][<>[]]}{{<><>}<
|
||||||
|
{{{{<((<<{({<(<>[])[<>{}]>{([]<>){[][]}}}[[{[]()}{{}[]}]{[[]{}]<<>()>}])}(<([<{}{})][[{}()]<()()>])(<([][])(
|
||||||
|
<{{[{[[[[{((((()())(()()))<<()>{()<>}>){[{[]{}]][(<><>)[{}{}]]}){{([<>[]]({}<>))((<>()){[]<>})}({<<>{}><
|
||||||
|
({({[<<<[{[{([{}()}{<>[]})[(()[]){{}{}}]}]{<([()<>]((){})){(<>{})}>[<{<>()}([])><{[]{}}<[]()>>]}}]{([(<[()
|
||||||
|
<{({(<{<((<([[{}[]][<>()]])[{(<>)(()[])}([<>()]<[]()>)]>)<<{[<{}<>>[[]()]]}[<((){})<<>()>>
|
||||||
|
((({(((<<[{<<([]<>)[{}()]>((<><>)({}()))>([[<>[]](<>{})][<{}{}>{[][]}])}]>>)))}){[<{{{(<<[[<{}()>
|
||||||
|
[<{<<{[<<<[{[{{}[]}[{}[]]]((<>[]){(){}})}{<<{}<>>{<>()}>(([]{}))>][{[<<>[]>]({{}{}}<[]<>>)}]>>
|
||||||
|
({{[(<{[{[{{(<()[]>(()()))<<{}()><[]()>>}[(<[]>[{}()])[<{}{}>(()[])]]}]}({{<<{[]<>}((){})><<[]
|
||||||
|
{(<[(<<<[({([((){})]({()<>}{[]<>}))({{<>{}}([][])})}{(({<>{}}<{}<>>)(({}{}){()[]}))[{([]())(
|
||||||
|
<{([[[(<{[{{{[()<>]}{[<><>][[]<>]}}((([]){{}[]})<<{}>(()<>)>)}<((<(){}>{{}{}})){{(()[]}[()<>]}{[[]()][<>()]
|
||||||
|
<[{{<([{{({(<{<>[]}{<>{}}>)[{{[][]}<<>{}>}[[(){}]<()<>>]]}<(({[]{}}({}{})){{{}{}}<<>()>})(
|
||||||
|
{[{{{([({{<<([{}[]][[][])){<[][]>(<>())}><<(<>())<{}{}>>(<[][]>{<><>})>>(<([(){}]<<>{}>)[<[]
|
||||||
|
(<(<({[[[<<{<[{}<>]([]())>{([]())[()<>]}}<{{<><>}[{}<>]}{[<><>]<[][]>}>>[({[(){}][{}()]}<<[]>([]<>)>)]>[<
|
||||||
|
{{[({[<[<<<<<{[]{}}<<>[]>>({[]<>}{[]()})><<[[]<>]>[<()<>>{<><>}]]>[[{<()<>><[]<>>}<([]{})(<>{})>]({([
|
||||||
|
{<[([([[<<<{{<()[]>[<>[]]}[[<>[]]([][])]}([[<><>]<()<>>])>({{[[]{}]{{}<>}}<[<><>][<>()]>}<[[{}[]
|
||||||
|
<<<<[[<[<[[{{[[]{}]{{}<>}}(<<>()>([]{}))}{[{()[]}{{}{}}][{<><>}(())]}]<((<{}[]>[<>{}])({[]{}}(<>{})))[<
|
||||||
|
<{[{({{{((<<[<<>[]>[{}()]]>{[([]())((){})]([[]()])}>[[({[]<>]{()()}){{()[]}{{}[]}}]<{{<>{}}([]
|
||||||
|
{{(<<{[[[[(<([{}[]]([]{}))>[{({}<>)<<><>>}({[][]}({}{}))])]]](<{<[({[]{}}([]<>))({{}[]}<()[]>)]{{
|
||||||
|
<{[<{[<<<<[<[<{}()><<>>](<()>({}()))>{[<<>[]>{<><>}](({}()))}]{{((()<>)((){})){({}[])<<><>>}
|
||||||
|
({<{[({([{({<<<><>>([]<>)>(<[]()>[{}()])}<[(()())<()()>][{{}{}}]>)}])(({{(<{(){}}<{}()>>[<<>()><{}<>
|
||||||
|
{{(({[([<((<{<{}[]>{<>()}}[[<>{}][()<>]]>))[[<{[[][]][[][]]}[<[]>(()[])]>{<[{}[]]{<>{}}><<{}()>[{
|
||||||
|
<([{{[[<{{[[{{<>}{{}[]}}(([]())[<><>])][[<[]{}>([]{})]{({}){<><>}}]]<<[<[]()><{}{}>][{()}[<>[]]]>{<<<>{}>(<>
|
||||||
|
{[[[([[(<<[{<<<>()><()[]>>}][<[<[]{}>(<><>))[<[]<>>[<>[]]]><<{[]()}{{}<>}><{<>}<<>{}>>>]><{<([()
|
||||||
|
<((<[<[([(({{{{}<>}{()[]}}{[<><>](()())}})>{<(((())({}[]))[{{}<>}{<><>}]){<[{}{}]{<>{}}>({()
|
||||||
|
[{[<<({({{<[[[[]<>]<<>()]]]([[<>[]]<<>{}>]<{[]<>}>)>}}{[[<[{[]{}}<{}[]>](((){}){<><>})>{<[[][]](<>())>
|
||||||
|
<[[{{[(<{<(([[(){}]{<>())]))[<[<{}[]>{{}[]}][{()<>}[[]<>]]>{{<<>{}><[]<>>}[([]<>)[[]]]}]>}<<<<{[()<
|
||||||
|
<(<<{{(<<({<{<[]()>}({[]()}[()<>])>(([()()][{}<>])<<(){}>{[][]}>)}(<{{[]{}}{<>()}}[{()<>}(()<>)]>))((({[{}][[
|
||||||
|
{<<<{({{<([[<{<>{}}[()()]><[<>[]]>][<<<><>>>[(<><>)<<>()>]]]([({(){}}[<>()])]<<<<>[]>>({{}[]}[()[]])>
|
||||||
|
[{<[{[[[({(<<[()[]]>{{()<>}{<>()}}>)[({[[][]][{}<>]}<<[]{}>[()<>]>){[<<>{}>{{}[]}](([]{}){[][]})}]}{{[(
|
||||||
|
{(<<<{{<[({([({}[])[{}()]]{(<>{})<{}{}>})(<(<>())>({()<>}<[]{}>))}<{<([][]]{()()}>}<<(<>()){[][]
|
||||||
|
((<{{[{{[([({[{}()]}[{()<>}(()<>)])]([([<><>]<<><>>)<{[][]}<<>[]>>]((<<>{}>({}<>))([[]()]<{}()>))))]}
|
||||||
|
[(<<<{<{(({(<<[]{}>><[[]{}][()()]>)[(({}{}}[<>[]])[({}<>){()[]}]]}))[(<<<{[]<>}>{[(){}][()[]]}>>[{[([]<>)([]
|
||||||
|
({({([<([{([[{[][]}{{}[]}]<[<>[]]({}())>])}(({<{()[]}{[]{}}>{({}())<{}[]>}})({{{{}[]}<{}()>}}))][[[[
|
||||||
|
([<[<{<[[<{[((<>())(()))[<(){}>{{}[]}]]{<{()[]}{[]()}><<<><>>>}}(<{[()<>]<<>()>}>)><{(([<>()]({}<>))([
|
||||||
|
[<[(({[<{{[[((())[<>[]])(<[]<>><<>{}>)][{{<>()}<()<>>}[{{}()}([][])]]]{{<<[]()>>[<{}()>[<><>]]){[{<>()
|
||||||
|
[(<([[<{{[(([<<><>>(()())](([][]]{<>()}))[<<[]<>><()()>>[({}<>){()<>}]]){{<(()[]){()[]}>}<(<
|
||||||
|
(<[{[<{[[{{([[{}()]<{}()>]<[()[]](()())>)[<[{}{}][[]()]><[{}<>]{{}<>}>]}}{{[{[{}<>][[][]]}<({}()){[]{}}>]
|
||||||
|
({{<[{<<<<[<<[(){}](<><>)>({{}()}{<><>})>}[({({}<>){<>{}}}<[()<>][(){}]>)[{(()<>)({}[])}]]>
|
||||||
|
<{<({<([[((<[{[][]}{<>()]]>{<([][])[[]<>]>[(<>{})[{}()]]})[{[({}())[[][]]]{{[]()}}}<[((){})[[]
|
||||||
|
<<<({{[<(<<{(<[][]>(<>()))({()[]})}[[<<>[]>({}[])]{[[][]]}]>{(<(())<{}<>>>(([])[<>{}])){(<<><>>[[][]])}}>(<[[
|
||||||
|
[<<({[[(<[[[{<[]{}>{()[]}}<[<>()]>](<{[][]}<<>()>><[[][]]([]())>)]](({{{{}()}{<>[]}}}<({[][]}[
|
||||||
|
<{[({{{<[(({<({}{})[[]<>]>(({})(<>{}))}[{<{}()>[[][]]}]))]>{<{{{([{}{}]({}{}))(<[]{}>({}[]))}{<{{}()}({}<>)
|
||||||
|
({{<((({({<[{[<>{}]([][])}]<[{[]<>}]{[[]()][[][]]}]>[{({{}{}}<[][]>){{(){}}}}]})<[(<<({}())<{}()>>({<>}{()()}
|
||||||
|
<{{{[(({([{<{<[]<>><<>[]>}>[[<[]{}>{()()}]<<(){}>>]}{[{((){})(<>())}<([][])}]}])[({<<{{}[]}>><{{<>()}
|
||||||
|
(<<<<<<[{{{[[{{}<>}(<>)](<[][]>({}()))]}<<[(<>[])(<>[])]({<>[]}<<>{}>)>{{{[]<>}({}<>>}([<><>]{<>[]})}>}
|
||||||
|
{[({<{{[({[[{[{}[]]{{}}}]({<{}>{()}}(({}{})({}[])))]{({{[]<>}{()[]}}<[{}<>][[]()]>)[{((){})(<><>)
|
||||||
|
{{<{{{[({(<{{{{}[]}{[]()}}((<>[])([]<>))}[{{<>{}}([]{})}{[[]<>]<[]<>>}]><{{(<>)}({[]}[()<>])}{<[[]
|
||||||
|
((<{{{{(([(<{{{}()}{<><>}}>)]{([{<<>[]>{<><>}}<[[][]]<()[]>>])({({[][]}<[][]>)[[[]{}]{[]<>}]})}))({{[
|
||||||
|
<<{<([{[{[<<<[()()]>[(<><>)[()<>]]>({[{}]<{}>}<{{}()}<[]{}>>)>][<[{<{}}}{[()<>]{<>()}}]([([][]){
|
||||||
|
(({<([[[({{(({[]<>}[()[]])[({}{})<()<>>))<(([][])<<>[]>){<[]<>>}>}(([<<><>>[{}<>]]{<[]()>{<><>}})([<<><>>(
|
||||||
163
advent_of_code/2021/d10/main.cpp
Normal file
163
advent_of_code/2021/d10/main.cpp
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
enum HOOKIES {
|
||||||
|
// PARENTHESIS = 3,
|
||||||
|
// BRACKET = 57,
|
||||||
|
// ACCOLADE = 1197,
|
||||||
|
// POINTY_BRACKET = 25137,
|
||||||
|
|
||||||
|
PARENTHESIS = 1,
|
||||||
|
BRACKET = 2,
|
||||||
|
ACCOLADE = 3,
|
||||||
|
POINTY_BRACKET = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned int line_score_corrupted(const string& s){
|
||||||
|
stack<HOOKIES> chars;
|
||||||
|
unsigned int score = 0;
|
||||||
|
|
||||||
|
for(auto c : s){
|
||||||
|
if(c == '(' || c == '[' || c == '{' || c == '<'){
|
||||||
|
if(c == '('){
|
||||||
|
chars.push(PARENTHESIS);
|
||||||
|
} else if(c == '['){
|
||||||
|
chars.push(BRACKET);
|
||||||
|
} else if(c == '{'){
|
||||||
|
chars.push(ACCOLADE);
|
||||||
|
} else{
|
||||||
|
chars.push(POINTY_BRACKET);
|
||||||
|
}
|
||||||
|
} else if(c == ')' || c == ']' || c == '}' || c == '>'){
|
||||||
|
if(chars.empty()){
|
||||||
|
score = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(c == ')'){
|
||||||
|
if(chars.top() == PARENTHESIS){
|
||||||
|
chars.pop();
|
||||||
|
} else{
|
||||||
|
score = PARENTHESIS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if(c == ']'){
|
||||||
|
if(chars.top() == BRACKET){
|
||||||
|
chars.pop();
|
||||||
|
} else{
|
||||||
|
score = BRACKET;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if(c == '}'){
|
||||||
|
if(chars.top() == ACCOLADE){
|
||||||
|
chars.pop();
|
||||||
|
} else{
|
||||||
|
score = ACCOLADE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
if(chars.top() == POINTY_BRACKET){
|
||||||
|
chars.pop();
|
||||||
|
} else{
|
||||||
|
score = POINTY_BRACKET;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int line_score_missing(const string& s){
|
||||||
|
stack<HOOKIES> chars;
|
||||||
|
|
||||||
|
bool corrupted = false;
|
||||||
|
|
||||||
|
for(auto c : s){
|
||||||
|
if(c == '(' || c == '[' || c == '{' || c == '<'){
|
||||||
|
if(c == '('){
|
||||||
|
chars.push(PARENTHESIS);
|
||||||
|
} else if(c == '['){
|
||||||
|
chars.push(BRACKET);
|
||||||
|
} else if(c == '{'){
|
||||||
|
chars.push(ACCOLADE);
|
||||||
|
} else{
|
||||||
|
chars.push(POINTY_BRACKET);
|
||||||
|
}
|
||||||
|
} else if(c == ')' || c == ']' || c == '}' || c == '>'){
|
||||||
|
if(chars.empty()){
|
||||||
|
corrupted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(c == ')'){
|
||||||
|
if(chars.top() == PARENTHESIS){
|
||||||
|
chars.pop();
|
||||||
|
} else{
|
||||||
|
corrupted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if(c == ']'){
|
||||||
|
if(chars.top() == BRACKET){
|
||||||
|
chars.pop();
|
||||||
|
} else{
|
||||||
|
corrupted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if(c == '}'){
|
||||||
|
if(chars.top() == ACCOLADE){
|
||||||
|
chars.pop();
|
||||||
|
} else{
|
||||||
|
corrupted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
if(chars.top() == POINTY_BRACKET){
|
||||||
|
chars.pop();
|
||||||
|
} else{
|
||||||
|
corrupted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
corrupted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int score = 0;
|
||||||
|
if(!corrupted){
|
||||||
|
while(!chars.empty()){
|
||||||
|
auto h = chars.top();
|
||||||
|
score = score * 5 + h;
|
||||||
|
chars.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
ifstream input_file("input.txt");
|
||||||
|
string line;
|
||||||
|
|
||||||
|
unsigned int total_score = 0;
|
||||||
|
|
||||||
|
if(input_file.is_open()){
|
||||||
|
while(getline(input_file, line)){
|
||||||
|
// total_score += line_score_corrupted(line);
|
||||||
|
|
||||||
|
total_score += line_score_missing(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Total syntax score: " << total_score << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
10
advent_of_code/2021/d10/test.txt
Normal file
10
advent_of_code/2021/d10/test.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[({(<(())[]>[[{[]{<()<>>
|
||||||
|
[(()[<>])]({[<{<<[]>>(
|
||||||
|
{([(<{}[<>[]}>{[]{[(<()>
|
||||||
|
(((({<>}<{<{<>}{[]{[]{}
|
||||||
|
[[<[([]))<([[{}[[()]]]
|
||||||
|
[{[{({}]{}}([{[{{{}}([]
|
||||||
|
{<[[]]>}<{[{[{[]{()[[[]
|
||||||
|
[<(<(<(<{}))><([]([]()
|
||||||
|
<{([([[(<>()){}]>(<<{{
|
||||||
|
<{([{{}}[<[[[<>{}]]]>[]]
|
||||||
2256
advent_of_code/2022/1/input.txt
Normal file
2256
advent_of_code/2022/1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
54
advent_of_code/2022/1/main.cpp
Normal file
54
advent_of_code/2022/1/main.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
ifstream input_file("input.txt");
|
||||||
|
string line;
|
||||||
|
|
||||||
|
int max_energy = 0;
|
||||||
|
|
||||||
|
// if(input_file.is_open()){
|
||||||
|
// int cur_energy = 0;
|
||||||
|
|
||||||
|
// while(getline(input_file, line)){
|
||||||
|
// if(line.length() > 1){
|
||||||
|
// cur_energy += stoi(line);
|
||||||
|
// } else{
|
||||||
|
// max_energy = max(cur_energy, max_energy);
|
||||||
|
// cur_energy = 0;
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
if(input_file.is_open()){
|
||||||
|
int energy_max = 0, energy_mid = 0, energy_low = 0;
|
||||||
|
int cur_energy = 0;
|
||||||
|
|
||||||
|
while(getline(input_file, line)){
|
||||||
|
if(line.length() > 1){
|
||||||
|
cur_energy += stoi(line);
|
||||||
|
} else{
|
||||||
|
if(cur_energy > energy_max){
|
||||||
|
energy_low = energy_mid;
|
||||||
|
energy_mid = energy_max;
|
||||||
|
energy_max = cur_energy;
|
||||||
|
} else if(cur_energy > energy_mid){
|
||||||
|
energy_low = energy_mid;
|
||||||
|
energy_mid = cur_energy;
|
||||||
|
} else if(cur_energy > energy_low){
|
||||||
|
energy_low = cur_energy;
|
||||||
|
}
|
||||||
|
cur_energy = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
max_energy = energy_max + energy_mid + energy_low;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cout << "Max. energy: " << max_energy << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user