diff options
author | Thomas Voss <thomasvoss@live.com> | 2021-12-10 06:34:40 +0100 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2021-12-10 06:34:40 +0100 |
commit | 3b458cb1b362856045611820dbec763c179e8712 (patch) | |
tree | dab2dd734c03b1b2c3cc63e339a9d92bd6dfc96a /2021/10 | |
parent | 1b250dfa1848e81943fa2f70976f8fa4669c8de9 (diff) |
Add day 10 solutions
Diffstat (limited to '2021/10')
-rw-r--r-- | 2021/10/.gitignore | 1 | ||||
-rw-r--r-- | 2021/10/Makefile | 8 | ||||
-rw-r--r-- | 2021/10/input | 106 | ||||
-rw-r--r-- | 2021/10/puzzles.py | 53 |
4 files changed, 168 insertions, 0 deletions
diff --git a/2021/10/.gitignore b/2021/10/.gitignore new file mode 100644 index 0000000..ffc46fe --- /dev/null +++ b/2021/10/.gitignore @@ -0,0 +1 @@ +puzzle-[12].py diff --git a/2021/10/Makefile b/2021/10/Makefile new file mode 100644 index 0000000..247194a --- /dev/null +++ b/2021/10/Makefile @@ -0,0 +1,8 @@ +all: + sed '/START PART 2/,/END PART 2/d' puzzles.py >puzzle-1.py + sed '/START PART 1/,/END PART 1/d' puzzles.py >puzzle-2.py + chmod +x puzzle-[12].py + +.PHONY: clean +clean: + rm -f puzzle-[12].py diff --git a/2021/10/input b/2021/10/input new file mode 100644 index 0000000..63c6ad2 --- /dev/null +++ b/2021/10/input @@ -0,0 +1,106 @@ +{{[<(<<<([{(({<>()}<[]()>)<({}{})(()<>)>){[([]()]{[]()}][<()()>{()[]}]}}[[(<[][]><{}{}>)]<[{{}()} +{<{<{[[[{[{<([[]()](()<>))>([<[]()>])}<{[[<>[]]<{}()>](<{}()>([]()))}<[{[][]}[<><>]][<()()>]>> +<<{[[<([<(<<([(){}])>(<<[]{}>(<>{})>({[]<>}{{}<>}))>)>]{[<[({<<>()>[()())}{([]())[<>[]]})([<(){}>]<<[][]>{{ +{[[[<({{{[{{({<>[]}[()()])[<<>[]>(()<>)]}<{{()()}[()()]}({{}()})>}[{[(<>{}){<><>]]<(()()){{}}>}<{{<>()}[[] +[<{[{[<[{[[({(()<>)}<{[]{}}<()>])<([[]<>][[]<>])(<<>()>{(){}})>]{{(<()[]>[<>{}]){([]{})}}[{{{}{}}(<>{} +[<<<{<<[((({{[{}[]]}}[[<()[]>(<>[])]{({}{})(()[])}]){<{{()()}{{}[]}}<{[]()}>>{<[(){}]><<{}{}>< +{[({[[[{<({[((<>[])([]{})){{{}<>}{(){}}}][<[{}{}]<{}()>><{{}()}<<><>]>]})>([[<[<<><>>{{}()}]<[{} +{(<(<{{(<[(((([]{})<{}[]>))(([[]()]{()<>})(({}{}){<>[]})))]{[([{<>{}}{()<>}]<[{}()]<<><>>> +{<[[[(<[{(<({[{}()]{(){}}}{{()<>}(()[])})({[{}()]{[]}})>)({{[{()()}[[][]])((<><>)<<><>>)}{ +{<{(<[(<{([<[<[][]>[()[]]]<{<>()}([]())>>]([{<<>{}><{}{}>}[[[]{}]<[]{}>]]{({()[]}){({}())((){})}})){([ +<[(((<{{<[[{<(<><>)<<><>>>{{[]<>}<()>}}<(<[]()>{()<>}]{([]<>)[[]{}]}>]](<{{({}<>)[[]()]}[([])]}<[<{ +({[[(<{[({<{<[{}()]([]{})>(({}{})(()<>))}<(<{}[]>({}()))[({}<>)]>>}[[([[(){}]([]<>)][(<><>)({}{}}])<{[{}()]}[ +[{{[(({[{{({(<()[]>{[]<>})}{[({}())]{<()[]>[{}{}]}})<(([()<>]{()()}){([]{})<[]>}){<<()<>>[<><>]>{<<>{} +{{<{[(<(({<{{<(){}>(()<>)}}[<<{}()>{{}{}}>([<>()]{<><>}]]>}(({{<{}()>([]())}{({}())}})<<{{ +{{<<<[{{<[(({[<>{}][[]()]})({[<>()]<<>[]>}(<{}{}>([]<>))))[[((()())[{}{}])[<[]()>[()<>]]]{[({}{}) +(({[({{<([<[{{(){}}<{}[]>}]([({}<>){<>[]}]{({}{})(()())})><{<[{}{}]{[][]}>{[{}{}]{[][]}}}{<[()]<{}{}>> +[{[({<({<<({((<>()))})<{<[[]<>](<><>)>}[{<<>[]>{<>()}}([{}{}]{{}[]})]>>>})>})<[[<[{{(<({<><>}{<><>})<<(){}>>> +{(<<{(<{<[[{<<()[]>{()<>}>}{(<<>()>({}()))}]]>([<[<<{}>[<>{}]>({[]<>}(()[]))]<{{<>()}<{}{}>} +{{(<([[<[({<{{{}{}}(<><>)}<({}<>)<{}[]>>>}[[({()<>}{{}[]}){<{}[]>{{}[]}}]<[{{}()}([]())][({}{})[{ +(<(<<{<[{{((<{{}()}[()]>({{}()}[[][]]))({{()[]}[<>{}]}{<()[]><()<>>}))[{[{[]()}[{}()]]([{}<>])}{<<()[ +[{(<<{[([[({<[{}{}){<>{}}><[()<>]([]{})>}{<[()[]][<><>]>[{[]<>}[<>{}]]})]]{<<[<({}[])>(<<>{}>[[][]])]><([{{}{ +[{([([[<{[[[<{<>[]}{()()}>((()<>))][{[{}()][[]{}]}]][{{(()<>)([][])}{({}{})(<>())}}(([{}{}]){< +<[{{({[[(([{[[{}[]]<<>()>][({}{})]}]<[<([]<>)><{()()}[()[]]>]<{(<>())<(){}>}<[{}<>][{}<>]>>>))<(((<{< +{<{{[{[{<<<{{([][])[<>]}<{{}<>}(<>())>}[<[()<>](<>[])>[[[][]]{()<>}]]>>>}<[[[{[({}())((){})]{(()() +{<{[(<{(<((({<<><>><<><>>})[[{()()}[()()]](<{}()>((){}))]))[{<[({}{})[{}[]]]([[]()])>((({}<>)[[] +[{{(<[[[{{[((<[]()>[[]<>>)[<()[]>])]({<[[]{}][{}{}]>{[[]]{<>{}}}}(<{[]{}}<<>{}>><([]<>){[]{}}>))}{[<{{[]() +{<<<(({{{{(<{{{}[]}}><[{(){}}<[]()>><<()()>({}())>>)<(({<>{}}([][]))<<()[]><{}()>>){[{<><>}[[][]] +{<[({({<<[{{{{[]{}}(()[])}<{(){}}>}<(([][]){[]{}})>}]{[{{<<><>>[[]<>]}}<[([]<>)<{}()>]{{{}{}} +{({<<[(([{(<((()[]))<[{}]>>[<({}[])[{}<>]>[{()()}<[]()>]])<((<(){}>(<>[]))<<<>><{}()>>)[<({}{}){ +<<[<(((<{{{<<{<>{}}<{}()>][([]())[{}()]]>[[{()<>}<{}[]>]<(()()){<>{}}>]}}<{([{<>()}<<><>>]{{()()}} +[(<<<[(([{[<(<()()>)[{<><>}{(){}}]>{{([]())[<>{}]}{{<>[]>[{}()]}}]}]))]>[[[{<((<(<()<>>){{<>[]}<[] +[{(<[((({{([(([]{})<{}()>)<[[]{}]{{}()}>]<{{<>[]}{[]()}}({<>()}[{}{}])>)[{{<[][]><<>[]>}[<{}{}>]}<<[[][]][( +([<(<<[(({[[<<[]{}]>{[()[]](()<>)}][({{}[]}{{}{}}){{{}<>}}]]<{({<>}(()[]))[<()[]>{[]{}}]}[{< +<<[<{{(([([<[[[]{}]<[]<>>][[<><>]{()()}]>]((({{}{}}(<>{})){([][])[{}()]})))<<([(<>)<[]{}>][{{}()} +(<{<([<[{[([(<[]{}>{{}})(([][]){[]{}})]<<({})[()()]>(({}[])[{}<>])>)(<[{{}{}}{{}[]}](<[]{}>[()[]])><<{{}()} +[{({{(({[{[<<[[]()]<<><>>>({()()})><[{<>()}{()<>}]<<()()><{}<>>>>]{(({<>{}}([][]})({{}[]}<<>()>))<<(< +{(<(<{{(((<({((){})[()[]]}{<{}()>{{}()}})[(<{}[]>[{}{}])([()[]]<<>()>)]>{[<[[]<>]<[]>><{{}<>} +{[[<{(<<<[{(((<>[])<{}<>>)<{[]{}}{<>{}}>)}[[{[{}{}][{}<>]}[(<>[])({}())]](<[{}{}]{()<>}>)]]([(((<>{})({} +{(<(({[([([((({}[])[()]))]([((<>())[[][]])])){{({([]())([][])}(<()()>{()[]}))}}]<{<(([{}[]](<>{}))[<[] +({<[[<<(<[(<[((){})]{[(){}][(){}]}><(({}())[<>()>){{()()}}>)(<[<()[]>(<>{})](<[]{}><(){}>)>[({[] +[<<[{{[<[<[[{[(){}]{<>[]}}[(<><>){{}{}}]]{<((){})(()[])>[[[]{}]{{}}]}]{(<{<><>}<{}<>>>)([(()[]){(){}}][ +(<<<((<[<[[[[{{}()}{[]<>}]<{(){}}[[]<>}>][<[[]{}]{{}<>}>{<<><>>([]{})}]]]{{{<{<><>}[{}()]>} +{{<<{[{[<[{(({{}()})(((){})[<>{}]))[[<[]{}>[[]]]{[[]{}]{{}{}}}]})>[{([{(<>[])[<>]}]<<[[]{}][<><>]>{{{}()}({ +[{{{(<{{[<{((<<>{}>[(){}])[(<>[])<[]<>>]][(({}<>)<[][]>)({[][]}{<>{}})]}({{[<>[]]([]<>)}}{( +<[([{[<<<[([(<(){}>{<>[]}){[{}[]]{[]{}}}]{({<><>})[[<>{}][[]{}]]}){<[<<>[]>[<><>]]({[]{}}{<>[]})>[ +[(<(<[({<[{{({()<>})<[()<>}<(){}>>}(({[]<>}(()<>))([()()]{<>}))}<{{([]<>)<<>>}[[{}<>]<[]()>]}<<([ +[[[<([[[[<<<((()<>)<[]<>>)(<{}()>[<>()]))>{((({}()))(<<>()>)){{{<><>}}<<{}<>>>}}><{{({[][]}<{}{}>)[(<><> +<<[({(<<<[{([(<>{})[{}[]]](({}[])))[<(<>[])><<()[]>[{}{}]>]}{([<[][]>{()()}][<[][]><[]<>>])}]>>>)}[{((<<([{(( +{(({[{{<[(<<<<<>()><{}{}>><<{}<>>[{}<>]>>((<()<>>)(<[]{}>[[]{}]))>((((<>())[[][]]){{()()}([][])}){<[< +({{{[(({<[[<[([][])(()[])](<{}<>>{{}()))><<(<>[])<{}()>>(<(){}>[<>()])>]]([<(<{}{}><[]()>)[[<>[]](()[]) +(<<[{[(({[({{{()()}(()<>)}<<<>()><<>[]>>})<{([<><>]<[]()>){<{}()>{(){}}}}>>}[{(<{[{}<>][<>{}]}([()()]({}() +({<<<<([{(([(<<>>{[]<>})][<<[]()>({}{})>])({(<{}[]>){([]<>)([]{})}}<[{[]{}}{<>{}}]>)){<{<[[]<>]([]<>)> +([{[[<((((<[[{<><>}(<>())]<(()<>){[][]}>]<[([])[<><>]](<{}{}}([]()))>>){{{[{<>{}}([]<>)]{[(){} +[{([[(({<[[{{(()[])(<>{})}<[()<>]{{}[]}>}{[<<>>[[]<>]]<[[]<>][<>()]>}]]{{[{<[]{}>((){})}<<<><>>{{}()}>] +(<({(<<({([<[{(){}}[[]()]]>[[[[]{}](<>())]]]{{({(){}}(<>{}))[[<>()]<<>{}>]}({[<>()]}{{[]<>}{[][]}})}]}){({{<[ +{([(((<{<[<{<((){})[<><>]>({[]()}<<>{}>)}}((<(<>())>{<{}()>{{}[]}}))]<{(({[]<>}<[]()>))<{{()}[()[]] +([[((([<[[{<[(()())][(<>[])]>[[[[]<>]{(){}}][[(){}]{<>[]}]]}({[<{}<>>(()())]<({}<>){[]<>}>}[(<{ +{([<{{{[{<[<<[<>()][<>[]]><<(){}>>>]<<({{}[]})<(()[])>>[<<[]<>>[()[]]><([][])[<>[]]>]>><[[[(<><> +<<{[<[{[[{{<[(<><>)[<>()]](<<>[]>{<>()})>{<{<>[])(<><>)><([]<>){<>()}>}}({([{}{}](<>()))<{(){}}([] +({<([({{{<{(({[]()}{<>[]})<{{}<>}[<><>]>)(<[[]]<()()>>]}>}}}){[{{<{<[[()[]]<()<>>]{{{}[]}{[]<>}}>}[{{{ +([{[[{<([<([({{}<>}<()[]>)<{<><>]{{}{}}>])[[{[<>[]]{{}<>}}({{}[]}<<>()>)]]>([{({<>}{()()})({{}{}}([]<>))}][ +{{[[((([{{[<{<{}()>}[(<>{})<{}()>]>({((){})([]<>)}([[]<>]{{}()}))]{[{{[]()}(())}(<<><>><<><>> +<{({[((<[<{[({<>[]}{{}{}})(({}<>)<()[]>)]({{{}()}[<>[]]}[<[]{}>[{}()]])}([{[<>()]({}[])}(<[][]> +<{[[{<<[<<<{({{}[]}[<>{}])<(<>())((){})>}<[<(){}>(<>())]>>(([<[]<>>{<>()]](<[][]>{()<>}))<([[][]]([]<>)){{()( +[[<[{[(({<<((<<>{}>[{}[]])){([<>{}]){{(){}}<(){}>>}>({<[{}<>][{}{}]><(<>{})>}[<({}{})[[]{}]>[[()()][{}]]])>} +({{<[<<[([{<<{[]()}{{}<>}>(<(){}>(<>{}))>}]<{[{{<><>}<<>[]>}(<()()><[][]})]{<[{}<>]<<>[]>>}}({{{()}( +[([(({[[<({[({()[]})([[]]{()<>})]<<{[]<>}{<>[]}>>}){{({[()[]](()<>)}({[][]}))<<[<>()]<[]<>>>[{{}<>}{()[]} +(<[<[([[{[<[[{{}[]}<<>>]{[[][]]<{}{}>}]({<()()>(<>{})}[<<>><[]{}>])><{{({}<>)[<>[]]}{[[]<>](<>())} +{[[[((([<[([(([]())({}{}))<<()<>>[(){}]>](<[<><>]{<><>}>{{{}[]}{<>()})))](({(<<>[]>)}){<<< +{<(<[<{{<<{[(<()[]>{{}<>})(<()()><[]{}>)]([{()()}<<>()>](<()[]>)}}([(<[][]>)[{{}<>}<()[]>]])>{<({<[]()>{ +[[[<[({([[{({(<>[])<{}>})<<<[]{}>>{[[]{}]{[][]>}>}[{<[<>[]](()[])><[{}<>][[]()]>}]]((<{{[][]}{(){}}}(([][]) +(<{<[<{({<[[[{()<>}[[][]]](([]{})[{}<>])][[<[]{}>{(){}}][<<>{}>[{}()]]]]<[{{()}(<>[])}((()<>)[{}[]])] +{[{({(<{(<(<{[<>()][()[]]}[({}{})<<><>>]><<(<>[])([]{})>])>)}(<<<([[{}{}]({})])({[[][]]<[]{}>}{[<>[] +[[[(<[{([[(([({}{})(()[])][<<>()>{[]()}])<<{<>{}}([]{})><(<>[]}<()[]>>>)({[<[]>((){})]<[{}<>][[]<>]>}{<<[][] +(<[<[(<<[<<<({{}[]}({}[])){(()<>){{}{}}}>>>[{[[<{}()><{}()>]{(<><>)<{}{}>}]([{[]<>}{<>[]}])}({{([]()){<>{}}} +[([[<<[(<[[{[((){})({}())][({}{})[()[]]]}({{()[]}}{[[]<>](<>())})]{(<[{}<>]{()()}>({<><>}((){})))}](( +{<[{([{<<(<{{{[]{}}}[([]<>)(()<>)]}<<<<>>[()<>]>{([][])(<>())}>>)<({{[()[]]{<>{})}<<[]{}>(()<>)>} +[[<[{[<{{<<(<[{}<>]{<>{}}><{<>[]}[[]<>]>)>[{[({}[]){(){}}]({<>()}[<>{}])}]>{([([{}{}][<>[]])[[{}{}]]]<{[() +{<({<{([<(<(<[(){}][()[]]><{<>()}<<>{}>>)<[{[][]}]{([][])<(){}>}>>[({(<>{})<<>{}>}{{{}<>}{[]<>}}){< +(<<(([{<[(<{({[]()}[[]{}])}([<())(<>{})]<(<>{}){<>[]}>)><{[<()<>>]{<()()>{{}<>}}}{{({}<>){ +[[<[[[<({<[{[{(){}}<()()>]}([{{}{}}{()()}][([]())<<>>])])[({<<<>()><[]()>>{([]()){[]}}}){{{[{}{}]<{}> +<[(<[(<{(<{[(([]()))]<{[[][]]}{[<>[]]}>}<{<([]<>)>}{[((){})<[]()>][({}{}){{}{}}]}>>{({{<{}()>[[]{}]}[(( +({(<[[([<{[([[<><>]((){})]{[[]{}]{()}})<[<[][]><{}<>>]((()[]))>]}(((((()())[[]()])({<>()}))<{[ +<<({[<<[<{{[([{}[]]({}))[{{}()}{{}()}]]{[<{}{}>]<{[]}{()[]}>}}}><[{<((<>()))<{{}{}}>>(<(<>{ +[(((<{[{<{<<{[[][]]{[][]}}>>{<{[[]{}][<>[]]}{([]{})({}{})}>{({{}()}<()<>>){({})[{}[])}}}}>[(<{{{(){}}}<({}[] +{<<(<{({[{<{<([]())[{}()]>[[()()]<()>)}<({[]()}<[]<>>)<{<>()}(())>>>}(([[{<>()}<<>()>]]{({()<>} +[[({<<[([{([[[<><>]([][])]<([]{})[<>[]]>][<[[]<>]((){})>])<(({()()}{{}{}}))({{()[]}([][]))[[<><>]<[]{}>])> +(<{<{[(([{[{<([][])<<>()]>{({}[])<<>>}}{<{[]<>}<[]{}>>}]{(<[{}[]]({}())><{(){}}{{}<>}>)}}][[{ +<{[[<[{(((([{[<>()][<>[]]}]<<{()<>}>(({}<>))>)[[({[]()}<[][]>){({}<>){[][]}}]((<{}{}>{()()}))])[< +<<<<[<[[[(<[{(()<>){()()}}([{}{}]<[]{}>)]>[{<<<>{}>{()[]}>({()}[()[]])}((({}())([][])))])]<([([<[] +{((<({({{{<<[{<>{}}(()[])]{(<>{})([]{})}>>{{{({})[<>{}]}{<{}>}}{{<[][]>[(){}]}{{{}[]}<<>()>}} +<[{[(((({{{[<<(){}>(<><>)>{{{}[]}<[]()>)]<<([][])([][])>[[<>()][[]<>]]>}((([{}])<<{}[]><()<> +[{[{<{[{<(([<(<>[])(()<>)>([[]<>]([]()))]<({{}<>}<[][]>){<<>{}>{[]()}}>))>[([(<{[]()}{{}[]}><(()<>){[] +[{[[[(([[[(([<{}[]>][[<><>]{()<>}]){[<[][]>]({<><>}[[][]])})({{{{}<>}{(){}}}<<()>[{}()]>])]]{(<<(( +(((([[{{<{[{<(()())(()[])>(({}<>){{}[]})}[<({}[])[[]()]><{{}()){<>()}>]]{[{<()<>><()()>}]{{<( +{[<[(({({<[(<{<>[]}>[{{}[]}{()[]}])[<[()[]]([]())>{[[]()]{{}()}}]]{<{<<>[]>(<><>)}>{([[]<>]{()<>})<{<>}>}}>}( +[({[{((([({(([[]<>]([]{}))<({}{})>)})(({<([]<>)([][])>}({<[]{}>[<>{}]}[<<><>>([]())])))][<<<({(){}}([]())) +[{<(<<{<({<{[({}<>)<{}{}>]{<[]{}>{<>[]}}}{{{{}()}(<><>)}({<>{}})}>{{<{{}()}<<>{}>>({{}}(()[]))}(({<>{}}[ +{(({<<{[((<((<{}()><()<>>)[<()()><{}[]>])[[<[]()>(()<>)][<{}()>{()[]}]]><<{(<>{})[[]{}]}[<[]<>><{}{}>]><{<{} +{{[{(<{({(<(<([]{})([][])>[{<>}<{}()>])(({()[]}[()<>>){(()<>)<{}[]>})>[(<([]<>)([]())>(<{}<>>[()[ +<[(<<[{[{[[<([{}<>]<[]<>>){[{}[]][{}[]]}>{<([]{})}<{{}{}}<<>()>>}]]}[([([{[]{}}<(){}>]{[{}{}][{}{}]})<<({}{} +{[<<[{{<<[{{[[[]<>]{<>[]}]<{{}{}}(()())>}<((<>[])<<><>>)>}<{[<[]><{}<>>]<[{}<>}{()[]}>}<([( +[<([({<<[{{{(<{}<>>({}())){[<><>][<>[]]}}<{<[]<>>{[]()})[([]{})<<>[]>]>}{{{[[][]]<{}[]>}[<[]<>>(()<>) +[((([[{<{[{{((<>[])(()<>)){{[][]}{{}{}}}}({({}<>)({}())}((<>{})[{}{}]))}]<(<((<>[])<(){}>)> +<({{({[{{<{([{()[]}(<><>)](((){})(()[])))({[<>{}]<<>[]>}[<<>[]>])}>}<[{<(<{}<>>)<{<><>}<[]>>>(([{}()] +[{{<({((<([(<[<>{}](()[])><{[]()}<<>()>>)[<(<>)(<>())>)]({({()()}[()[]])}<[[[]<>]<{}<>>](({}[]){ diff --git a/2021/10/puzzles.py b/2021/10/puzzles.py new file mode 100644 index 0000000..0554d25 --- /dev/null +++ b/2021/10/puzzles.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +# START PART 1 +from collections import Counter +# END PART 1 + + +def main() -> None: + with open("input", "r", encoding="utf-8") as f: + data = list(map(lambda l: l.strip(), f.readlines())) + + # START PART 1 + counts = Counter() + # END PART 1 START PART 2 + scores = [] + # END PART 2 + + for line in data: + stack = [] + for char in line: + if char in ("(", "[", "{", "<"): + stack.append(char) + elif (stack.pop(), char) not in (("(", ")"), ("[", "]"), ("{", "}"), ("<", ">")): + # START PART 1 + counts[char] += 1 + # END PART 1 + break + # START PART 2 + else: + score = 0 + for char in reversed(stack): + score *= 5 + if char == "(": + score += 1 + elif char == "[": + score += 2 + elif char == "{": + score += 3 + elif char == "<": + score += 4 + scores.append(score) + # END PART 2 + + # START PART 1 + print(counts[")"] * 3 + counts["]"] * 57 + counts["}"] * 1197 + counts[">"] * 25137) + # END PART 1 START PART 2 + scores.sort() + print(scores[len(scores) // 2]) + # END PART 2 + + +if __name__ == "__main__": + main() |