diff --git a/2021/day10/10.py b/2021/day10/10.py new file mode 100644 index 0000000..27a63e4 --- /dev/null +++ b/2021/day10/10.py @@ -0,0 +1,22 @@ +lines = open("input.txt", 'r').read().splitlines() + + +di = { + ')': ('(', 3), + ']': ('[', 57), + '}': ('{', 1197), + '>': ('<', 25137) +} +score = 0 + +for l in lines: + stack = [] + for c in l: + if c == '(' or c == '[' or c == '{' or c == '<': + stack.append(c) + if c == ')' or c == ']' or c == '}' or c == '>': + if stack.pop() != di.get(c)[0]: + score += di.get(c)[1] + break + +print(score) \ No newline at end of file diff --git a/2021/day10/input.txt b/2021/day10/input.txt new file mode 100644 index 0000000..674cd38 --- /dev/null +++ b/2021/day10/input.txt @@ -0,0 +1,110 @@ +{{{[(<<[[[<<([[]()]<()<>>)((()()))>([(()><{}[]>]({()[]}))>{[{(<>[]){{}[]}}<({}()){{}[]}>][<<(){}>(()<>)>{[{ +{<<((({{<<[<<{[]()}(())>([[]()])><[[{}{}]<[]<>>](({}())[{}<>])>][([{[]{}}](<<>{}>{()()})){({[]{}}<<><>>}{({} +(<[{<{<(<[[<<<[][]>(<>)>><{<(){}>{[]{}}}<{{}[]}{()[]}]>][<([{}<>]<[]<>>)<{[]()}[()<>]>>[{{<><>}<<>{ +([{([{{{<[[{[{{}()}<{}[]>]{{<>()}<()>}}{<<{}()>{<>{}}>}]]<(<<[<><>]<<><>>>{<{}()>({}())}>){(<{()<>}><<< +{(<{[{[{([<<{<()()>((){})}[[{}{})<()[]>]>>{([<{}<>><<>[]>]<{<>[]}[{}<>]>){<[<><>]{{}{}}><( +[<([<(<{[<[{<<()[]>{()[]}>}{<[{}][[]{}]){[()()]{<>[]}}}]>{(<(<[]()><{}<>>)(<{}<>><{}()>)><<(<>())>>) +(<{<[<[(({([(([][])([]())){(()[]){[][]}}][({[][]})[[[]{}]({}[])]])}{{{[{<>()}{()[]}](<{}[]><[]<>>)}<( +<<(({([[[([{[[()()]{<>[]}]<[<>[]]({}[])>}]((<[[]())(()<>)>(<{}()>([][])))<([<>[]](()[]))>))[<[[<{}<>>([][])] +(({[{[{<(({([{[]{}}(()())]{{()()}<<>()>})([{{}{}}[{}{}]]<<(){}>[()<>]>)}<{{(()[])}}{{[[]() +[<{<<<{<[[[[(((){})(()[])){<[]{}>}](<[<>[]][<>()]><[()<>]<<>[]>>)]({{[<><>]}<<<>{}>[{}<>]>}[{{{}{}}([]{})} +{[<({<{{<([(<<<>{}>{<>[]}>{{()<>}<<>{}>})(<<[]>((){})>)][<[<()<>>[()]]<((){})<<><>>>>[<{()[]}<{}[]>>]])>}{{< +([[<{([{<<[{<[{}<>]{<>{}}>{[(){}][()()]}}<{(<>[])(<>())}([<><>])>]>{{{<([][]){<>()}>{([]()><()()>}}{{({}() +(<[[({{<([[[[{{}<>}[<>()]][(<>[])<<>()>]]]([([[]()][()()])]([[{}[]]<{}[]>]{[{}<>]{<><>}}))))>( +<<{[([(<<({{([{}[]]<<>()>)<<()[]>[{}<>]>}({(<><>)[{}()]})}[{<[(){}]>{{<>[]}[<>{}]}}[<(<><>){{}[]}>{{<>{ +[<({[({[<{[(<[{}()][{}<>]>{{()[]}(<>())})({{{}<>}<[]()>}{<()<>>})]}[<<{{[]}({}{})}([[]<>][()<>])>>[[[ +(<<[[<{<(<<<<[()[]]<<>()>>({[]<>}[[]()])>([<<><>>](([]()){[]()}))>{<[{{}<>}<<>[]>]<<<>><[]()>>>{ +<[[{[<({{[{(<([]())<{}[]>>(<<>{}>{<>})){[{[][]}{<>[]}]{[[]{}]<[]>}}}<<(([]{})[<>{}]){[{}()](<>{})}>[[([]{})[{ +([(<[<[[{([[(({}{})[(){}])([<>[]]{()[]})]([[()<>][<><>]])]{[<{[][]}[[][]]>{<[]()><()[]>}]<[(<>())<<>{}>]>})} +([([{<<{{{({<<<>[]><<><>>>[[<>[]]<[]()>]}<<{[][]}[{}<>]>{[<>()]{()[]}}>)[[[<<><>>{(){}}>[({}[ +[[<[[({{(<[{<{[]{}>>({[]()}{[]<>})}{(([]{})[<>{}])[(<>{})<[][]>]}]>){{<[{<{}<>>}<([][])([]<>)>]((<(){}>(() +([[{<[<((<{([{[]<>}({}[])]){{[[]]{<><>}}[<[][]>([][])]}}{[(((){})([]())>]{{{[]()}<<>()>}}}>){<[( +{<(<{{<{[{<{{<(){}>{<><>}}}[{[{}<>][{}<>]}[[[]{}](()[])]]>}][<<<{[{}[]]<()()>}(((){})[()[]])>)((<(() +{([<{<{([(<{[{{}[]}[(){}]]<{()}<{}()>>}[[[[]{}]{<>[]}}]>{[[[<>]<<>()>]{<()<>>{[]<>}}]})<<{[{<>()}<{}<>>] +{<<(<[<[[[[{{(()())([]<>)](<<>>({}()))}<[{<>()}[()<>]]>]({[[[]()]<()<>>]}[[<[]<>><()<>>]{<{}()>[ +[<{(<<[<[(<[{(<>{})<{}()>}]<[[()<>]{<>()}]>>)]](({<{<[()()]{[]()}>((<>())(<>{}))}{[<{}()>]<(<>[ +[<({({[[[<{<[[()<>]<<><>>]{([]<>)([][])}>[[(<>[]){(){}}]]}{{<{<>{}}<<>>>(([]{})[[]<>])}[<(()[]){{}{}}>]}>[{ +{(<<{<[{[{({{[<><>]{{}[]}}}(([{}[]]<[]<>>)})[<(<[]{}><<>()>)[<{}<>>[<>[]]]>(<((){})[{}<>]>{( +[<(({<<([{[{{{<><>}([]<>)}}]}](<(<[([][])<{}[]>]{{{}{}}[{}{}]}>{(<[][]>{{}{}})})>)){[([{{<[][]><()>} +[({[[[(<<((<(<{}()>([]<>))(<()()}<{}[]>)>(([{}[]](<>{}))[{[]<>}(<>[])])))>>)][<{({<[[<{}{}>{[]()}]{(<>{}){ +{(([((([<[{[(({}[]){()<>})[[{}[]]({}())]]{<[[][]](()<>)>{[{}[]]{[]()}}}}<{(<<><>><()<>>)<({}[]) +{([{{[[{<({([[<><>]<{}<>>]<[()[]]<()[]>>)}[[{[{}{}]{{}{}}}]{[{[]{}}([]{})]{(()())[<>()]})])>}]< +([<[{{{([{{<[[{}{}]]{<()()>}>{{{()[]}([]())}}}<<{<[][]>{<>{}}}>{[[{}()]([]{})]{([]{})(()())}}>}])<<<((<<{}{} +[{{[<[[[<({[[<(){}>{{}[])]{{[]<>}([])}]}<({{<>()}[{}{}]}{[()()]{[]<>}})[{[()<>][()[]]}]>)>[<(<{{ +(<{{({{{[({([({}[])<{}{}>](([]{})[{}{}]))})[(<<((){}){()<>}>[[[]<>][{}[]]]>{<([]){{}<>}>([[]{}])}){[((( +<[<{{(<(<<[{([(){}][()()])((<>())]}]>>)>)}[{(({({[[{(){}}]][{(()()){{}[]}}<(()())(<>())>]}{([{[]<>}<[]<>>] +{({<[[<<{<{(({<>{}}<<>{}>))[<<{}()><<>()>><<(){}>({}())>]}<(([{}[]][{}{}]){<{}>}){[<[][]>(( +(<[{{[{([<<<(((){})([][]))>([[<>{}])[<{}()>{<>{}}])>>{{{{<[]{}>[()()]}[(<>{}){<>{}}]}{([[]{ +{(<[{({<<(<<<(<>())[{}[]]>>{([()()]({}{})){<[]()>[[]<>]}}>[[<[{}{}]{{}<>}>{[<>()][<><>]}]{<[<>][[]<>]>((<>{ +{[<<(<<({(<<[{<>[]}]{[{}{}]<[]()>}>(((())<<><>>)((<>{})[{}[]]))>[<({<><>}[[]{}])[<()[]>{()()}]>{{({}[])({}() +<<<(<((([<{[{{{}<>}{{}[]}}[(<>)<<>[]>]]<[([])]<{()()}{<>{}}>>}><{<[[[]<>]<{}<>>]>[(({}[])<[]<> +{<(([[{{[({(([[]{}]<{}()>)<([]())[[][]}>)<<<<>>{()[]}>[<<>()>]>})<<[({[]<>}[[]<>])<<{}()>({})>]{<<()[]>(()[ +([<([{<[<{<([<()>({}[])](<<>{}>{{}{}}))<<({}{}){{}()}>[([]{})[[]()]]>>{{<[()<>]{()<>}>((<>())[{}<>])}<[(< +<([{({({<({[[(()[])[[][]]][(()){()[]}]](<{()<>}(()())><[[]()]([][])>)}{[{[<><>][{}{}]}<(<>[]){{}[]}>] +(({[<<[[{{<[{{[][]}(()[])}{<()<>>}]([<[]<>><{}<>>]{<{}()>[<><>]})><{{<<>{}>[[]{}]}{<{}<>>[[]{})}}<<<{}<>> +<{{<(({{(<[<<[[][]]{[]()}>><<{()[]}{<>)>(({}{})(()()))>]{(<({})({}{})>([()()]<{}<>>)){([{}[]]([]{}))[<[] +{({[<<[[<[<(<{<>{}}{{}()]>([{}[]][()[]])){{[()[]]{<><>}}({<>()}[<>()])}><<{[()<>]<[]>}<({}[] +<{{<<{<{<([(([<>()])<({}())<{}[]>>)[[(()())[()()]]{{()()}<{}()>}]])<[([<{}{}><[][]>])[[<[]<>>{[]<>} +<{<([[<{[{([[[[][]]<[]<>>][({}()){()()}]]<(([]())[<>[]]){[()<>]}>)[[<<{}<>>([]{})>[(()<>)[[]()]]]]}((((<<>> +[[{[<<([[({{<<{}<>>{<><>}>[<(){}>([]<>)]}<{<{}[]>{()[]}}((<>{})<()[]>}>}[<([[][]]([][]))({()()}<() +[{[[{(<({(<({({}<>){{}[]}}{<<>[]>{()[]}})<(({}())[[]{}])>><[<{{}[]}>{<[][]>[()]}]{((<>{})(<> +{{<{[[[(<({<(<[][]><{}<>>)[(<>{})<<><>>]>})>)]]]}{([[<<{[{<<()[]>({}{})>({{}()})}]<{[{()()}]<[[]]<()>> +[{{[<((<<(({{[[]()]([]())}{<[]{}>[{}{}]}}<({<>{}}{()[]})<{{}}{{}[]}>>)(<<<{}[])<[]()>>({[] +([[[<(<([{(({{{}[]}[{}]}[[()()][{}{}]]}({(<>{})({}())}({()()}([]<>)))){{({()<>}(<>[]))[(()())<[][]> +{([<<{<(<((({({}[])({}[])}([<><>]([]())))<<<[]{}><<><>>>({{}[]}{()[]})>}(<[({}[]){<>[]}](<[][]>{{ +{{(<{<([[<[[(((){})<{}[]>)[[[]<>][<>()]]]{((<>[])(<>())){<<>>([]{})}}]<[([[][]][{}])]>><(({{<>()}}[<[][]>]) +{[[{<<<{{{[[(<(){}>{[]{}})]]}({<[[{}()][{}{}]]{({}[])[{}<>]}>{{{[]<>}[<>[]]}<{[][]}(<>[])>}})}{[<{[([][]){< +<[<{<[{<({(<<([][])<()[]>><[<>()]{{}()}>)<([()<>]<<>{}>)(({}<>)[()<>])>)})>}][(<<<[[({{}()}{{}[ +<{{(<<{[{<{{{{[]<>}{()()}}{(<>()){()[]}}}[{(<>[])}(({}[])[()[]])]}<<[{<>()}]<{<>()}<{}()>>>{((< +{[<[{{[[<[{<<[[][]]<{}[]>>><<<()[]>({}[])>>}([[[[][]]]((<>())<<>()>)](<[{}()]<[][]>>({<>[]}{[]()}))>]{{<[{{} +<([[{[{<<(<{<[{}[]]{(){}}>(<{}<>>{<>()})}{(<(){}>{[]))((()<>)[{}[]])}><(<<(){}><()>>){(<()<>>(()()))<({}())[ +{<(<<{<[<<<[[<[]{}><[]()>]<{{}{}}{{}<>}>]>[[(<<><>>((){}))]({<()()><{}{}>}({<>()}))]>>]([(({<{()()}[ +([{[([({[[<[{(<>[])<<>()>}[[{}[]]<[][]>]]><(<<()<>>({}<>)><(()[])(()())>)({[[]{}]{<>()}}{[[] +[(({([{[<<[{{((){})({}())}}]{{{<()<>>[[]()]}((<>[])(<>()))}[[[<><>]([]())]({()[]}{()[]})]}>>({[[<< +<{{(([[[<(<(([[]()]<[]{}>))[<[{}{}](()())>[[()<>](()())]]>{<{<()<>>}(<{}<>>[[]()])>})>[({< +[<{([{{<<{{(<([]{})[<>{}]>[<()<>><()[]>])({(()<>)<<>[]>)(([]{})([]<>)))}}>[{[({({}())[(){}]}<( +<([<<[<(<<<<({()[]}<{}<>>)[[()[]][[]()]]><({{}{}}){[[][]]}>>{[((()[])[[][]]>{{()()}{()<>}}]<{< +<((<{<{<{<<[[<<>()>{<>}]{({}[])<<><>>}]([{()<>}{[][]}]([[]<>](<>())))>[<<[[]<>]<()()>>[{()()}<(){ +<<{[{[{[<{{<<[<>()]<[]<>>>[[()()][{}{}]]>([{{}[]}<()<>>])}[((([]{})[[]<>])<<{}{}>{<>[]}))]}><[{( +{{{{<<[{<{(({<{}()><[]<>>})[{<[]{}><()()>}{<<>[]>[[][]]}))<{<[<>[]][[]{}]>{[(){}][[]()]}}{{ +<<{([({{[{{<[<[][]>{[]<>}][<[]()>]>{{[{}][()[]]}({{}[]}[()[]])}}{[[<<>{}>](<()()>)][<[[]{}]<{}{}>> +[{{<{([[<{(({<[]{}><[]()>}<<()<>><<>()>>)<{(<>()}[{}<>]}>){(<{<>{}}({}[])><{()<>}>)}}[({(<[]()>({}<>))<[[] +{{{({({<{<{[[{[]{}}{[]()}]<{{}()}<{}[]>>]({<[]<>>[[]()]}<[<>[]}<{}<>>>)}{<<(()[])<()[]>>[(<>[])<()[]>]>(<[[]( +<{[(([[[([[<[[{}()]([]<>)][(()[])[<><>]]>(([<>{}]({}()))<{{}}[[][]]>)]({{<{}[]><[]()>}({[]{})[[ +{(<({({(<(<(([<>()][{}<>])<{()<>}<{}()>>)[[[()[]]<[]{}>][[()<>]<[]{}>]]>{<<<[]><[]()>><(<><>)<[]{}>>>})(([ +<{<(([(<<<<<{(()<>)}{<()()>(<>[])}>>>>>){{(<<[[{<>[]}(<><>)]<{[]{}}>]>>)[([{[[<><>]<()()>]{(()[])<<><>>} +({{[(<([({((([()[]]{{}{}})[(<>{})([][])])){{({<><>}[()()]){<{}[]>[<><>]}}}}{(<[<<>[]>]>><<[{()}<()()>] +([{[[([{<[({{({}[]><[][]>}}((<()()>[<>[]])<({}())({}())>))]<[[[(<>{}){[]}]{{[][]}{()[]}}]]<{<<{}<>><< +({{<[[({{((<[{()<>}[{}[]]]([[]()](()[]))>{[{()[]}{{}[]}][{{}{}}{[]{}}]})({{[{}](<><>)}[([]() +[<<{[{({{[[{{<[]{}>[<>[]]}<({}[])[()[]]>>{[[<>()]{{}[]}][{[]{}}{[]()}]}][<<([]()){[]<>}>((<>){{}()})>[{{{}( +(<{[{<{[[[<[<{{}<>}<()>>{[<><>][()()]}][<[<>()]{{}{}}>([[]())[[]<>])]>]{[(<[()()]{<><>}>{[{}[]]< +<{[[[{(({{<({(()[])(<>{})}(<[][]>[<>]))({([]<>)<<>[]>}<[<><>][()()]>)>[<[[<><>][()()]](<()>[()<>] +[<[([[<<[{((<[<>{}][{}[]]><(<>{}){[]<>}>))}][{{<<<[][]><{}<>>>><({()[]}<()[]>)>}<([<(){}>({}())]<[{}][()]>)[ +[([({{[[{{[[{{{}{}}<[]<>>}]]<{{{{}{}}<<>()>}((()())({}[]))}[[<(){}>(<>{})][[<>{}]{{}<>}]]> +<<[{<<([[({([[[][]]{{}()}])[[{{}[]}<{}()>]{[(){}]{<>[]}}]}([{{[][]}>]<{{()[]}<()[]>}<(()<>) +[[[{(<[[{(({<({}())>{{<>{}}[{}{}]]}<{{()()}[{}<>]}[<{}<>>(<><>)]>))<<<{<<>[]>}{[{}()][{}{}]}>[<[(){}][{}{} +{<([{[[([{[{(<()()><<>[]>)(({}{})[{}<>])}[<<()[]>[()<>]>{({}<>){()()}}]]<<{(<>[]){()()}}<{{}[]}(<><>)>>(( +(({{<(<({[[{({{}[]}([][]))[{[]<>}<<>[]>]}[<{[]{}}([])>]]{{([<>[]]({}()))(<()<>>{[]{}})}}][{<<{<>() +{{[<[<(([<{[([()()][[]<>])[<()<>>{()[]}]]}>[{({{()()}([][])}({()}(()<>)))[[({}())]{{<>()}[<>]}]}]]{<{({({ +{{([([({[<((<{<><>}>{(<>[])})([({}{}){<>()}]))<[{<{}{}>{<>[]}}]<(<(){}>{()<>}){<<><>>}>>>[{[ +[<{<[(<{{[((<[<><>]{(){}}>(([]<>)[()()]))(<{{}()}[{}[]]>{<<><>>{()<>}}))({[<()()>{<><>}]<{[]< +<((([(<[{<<[<<<>()>({})>][((()[]))<{{}()><<><>>>]>>({[[[<>{}][<><>]]({{}()}<{}{}>)]}((<<[]> +[[{({[({[[[[<[<>()]{<>{}}>]{([<>{}](()<>))[[{}<>]({}[])]}]{{{(<>{})({}[]]}}[{[()<>]{()()}}]}]]<<{[((<>())<()< +{<{{{([(<([<[{<>()}{<>{}}]<([]{})<[][]>>>([<(){}>[[][]]]{<()<>><<>[]>})]<<<[()()]>>[([()()] +[([[(({[[{{<{(<>{})<(){}>}[({}{})[<><>]]>({<<>{}>[<>{}]})}}[[<{<()><{}{}>}{{<><>}}>([[()()]{{ +{{[({({([([<({()}([]()))>[[(<>[]){<><>}][{[]{}]<{}>]]]{{[({}{}){<><>}][[[]<>][<>[]]]}((([]< +{{<<[<<(({[[{{{}()}({}{})}<{()[]}{()()}>][{{<>{}}[()<>]}([{}[]]{{}[]})]]<[{{[]<>}{<>{}}}{[<>[]]<[][]>}] +[{<({({<{{({{{<>{}}<{}()>}{(<>())[<>{}]}}[(<<>{}>[{}])])((<<<><>><{}()>>(<<><>>([])))(<([]<>)>{{ +{[<[((<{{[{{<({}{})>}<((<>)<[]<>>)[[<>()]{{}}]>}]}}>))]({[{{([[<<<{}[]>><<<>()><<>[]>>>[{{(){}}}<[[]{}]({} +<<<[<({[(<(<<(()<>)<{}{}>>{([]<>){<>{}}}>{{<{}<>>(<>{})}<[()<>]>})<{[({}())[<>[]]]({<>()}<<>{}>)><{ +({<<[{<<[{{<([(){}]<<>()>)<<<>()>[[]()]>>(<{<>()}([]())>{[[]<>](<>{})})}}]]{<(<<[<<><>>((){})]{ +<([{{[{<<[[{{[{}[]][()]}<[{}()][[][]]>}}[<{[<>[]]{{}()}}>{(<()()><[][]>)({()<>})}]]<[<[<{}<>>([]<>) +([<<[[([(<<[({()<>})<{[]()}{()}>]({{()<>}})>{[([<>()]([]()))[{[]{}}]]}>{{{(<[]()><[]>)<{{}{}}[{ +([[{[[{<{[{<({()()}[<>{}])<<{}{}><<>()>>><[[<>{}](<>()]]<<[][]>{<>{}}>>}][<{(<<>()>[()[]])<{<>{}} +<{<<{<((([{[<(())<{}[]>>]<(<{}()><<>{}>)<<<>{}>>>}<{{<<>()>{{}()}}<<(){}>>}[[{[]()}({}())]((<> +([[([(<[<<{[<[()<>][[]()]>[[[]<>]<()()>]][[(<><>)]<<<>>(<>[])>]}><{([(<><>)]{[()<>}})}>><<[[(< +{{(<<({<([([{{[]()}}([<>{}]{{}()})])])[[[[[[<>{}>({}())]{{[]{}}({}())}]]([{{<>}(()<>)}[{<>()}<[][]>]])](<[[[ +((({{<[<<{{{<<[]()>[<>[]]>[({}[])([]{})]}<<[[]{}]<()<>>><({}())(())>>}[<<[(){}]<[]()>>[{{}<>} +[<([<{[([[[(<[<>{}]({}{})>([()[]]({})))([{()()}{()[]}]<[<><>]{()()}>)]({({(){}}{<><>})<[<>()]{{}() +<(({(<[[{[{[((<>())[{}])[[<>]{<>()}]](<{[][]}{<>()}>([<>{}>{[]<>}))}[[({<>{}}{<>()})((()[])<<> +<{{{{<{[[<[({{<>[]}(()<>)})<(<<>{}>[(){}])[{<>{}}{<>{}}]>]({[{<>()}<()<>>]{<[]()><{}()>}}([ diff --git a/2021/day10/input.txt.sample b/2021/day10/input.txt.sample new file mode 100644 index 0000000..2f182d8 --- /dev/null +++ b/2021/day10/input.txt.sample @@ -0,0 +1,10 @@ +[({(<(())[]>[[{[]{<()<>> +[(()[<>])]({[<{<<[]>>( +{([(<{}[<>[]}>{[]{[(<()> +(((({<>}<{<{<>}{[]{[]{} +[[<[([]))<([[{}[[()]]] +[{[{({}]{}}([{[{{{}}([] +{<[[]]>}<{[{[{[]{()[[[] +[<(<(<(<{}))><([]([]() +<{([([[(<>()){}]>(<<{{ +<{([{{}}[<[[[<>{}]]]>[]] \ No newline at end of file diff --git a/2021/day9/9a.py b/2021/day9/9.py similarity index 100% rename from 2021/day9/9a.py rename to 2021/day9/9.py diff --git a/README.md b/README.md index 28a344d..0c8d07a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ my solutions for the [Advent of Code](https://adventofcode.com/) in progress:\ -2021 (python)\ +2021 (python) planned:\ 2022 (rust)\