diff --git a/day10/input.txt b/day10/input.txt new file mode 100644 index 0000000..1115e8e --- /dev/null +++ b/day10/input.txt @@ -0,0 +1,110 @@ +[<(<<([[[{<[{[[]()](<>())}<{()[]}<[]<>>>](<[()[]][()()]>)>[{{(()())(<>())}({()[]}{{}{}})}[( +{{{(({[<<[{[(<()()>[<>{}])<<()()>[[]]>]{{<(){}>{()[]}}([()<>]<<>{}>)}}([[<[][]>({}{})]<({}[]) +<[[[(<[{{{(<({()<>)([][]))(<{}()>{[][]})>{[[{}()][[][]]]({{}[]}[()()])})}[{<([()()]{()<>}){([] +[{[(<<{({{<<<{<>[]}{{}}>[({}<>){<>}]>[<<{}()>{<>[]}>[(()())({}())]]>}}({[(<({}{})<<>{}>>{<()()><[ +{{[{<<{[<{([({[]{}})])}>]}>><<<[[[<[([<>{}])<{[]{}}(<><>))]>]]({([{(<>())(()[])}<<()<>>>]< +((<<{<[{[((<([()[]])<{<>{}}>>((<{}[]><(){}>)[<()<>>(<>())])}[<{<()[]>{()()}}>])]([{<{<()[]>({}<>)}>}]{ +{<[<<({{<<{(<<()()>((){})>[{<>()}{(){}}]){(<()()>){([]{})[()]}}}[([<<>[]>{{}}])]>>(<{([[[][]]({ +<({{[[[[[<[(<((){})({})>)[<({}<>)(<>)>{{<>}}]]><[<{[[][]]<<>{}>}{(<>()){[]{}}}>{({()}<()[] +<<{<{{[[([<{{[(){}]<()[]>}<{<><>}[[][]]>}>[[[<()[]>]<{<>()}<[]{}>>]}]{<(<<<>{}>(<>[])>[{()( +({{(({<([(<{{[[][]]<{}<>>}{{[]<>}}}>[({{()<>}(<>[])}<<<>[]>>){[([]{})]<{()<>}{(){}}>}])[<[{[{}[]]}[ +<([<{[{(<[[[((()[])[[]()]){[[]()](()<>)}][<(<>[]){()()}>{(<><>)[<>]}]]][((({{}[]}{[]()}))<[[{}<>]<[] +{[[([<[<{({{{[<>{}]{(){}}}{{[]{}}<{}<>>}}<(<()<>>{()[]})<(<>())[[]()]>>}[<[{[]<>}(()()))<<[]{}>{< +{<<<(([(((<[{(()[]){()<>}}]>)([<[<<><>>((){})]>][{[[{}[]][{}<>]]<<()<>>[{}[]]>}[[<<>{}>[{}[]]]<{[]()}>]] +{{[(<<<(({{<<{{}<>}[<>[]]>([[]<>]<{}{}>)>{({{}{}}{[]<>})}}}[[{<{<><>}(<>())>{[()]}}<[(<>{}) +((({([{[[<{{([{}][{}<>]){[[]{}]{{}<>}}}[<{<>{}}><[[]{}]<<>()>>]}([(<()[]>[<>])[[[]()](())] +({{<[{{<(([<{<<>[]><{}{}>}[(<>{})<()[]>]><[[[][]](()())](<[]()>(<>[]))>]{<{<{}[]>[{}[]>}><[[[]{}]<[]{} +{{<[{<[<{[{((<[]<>>{{}[]})[([]<>)(()())])}][({[({}()){{}<>}]}({<[][]><<><>>}<[()<>]<[]<>>>))(<<<<>{}><(){}> +{[<[{<{((<[(<([][])[(){}]>{([]())<[][]>})<{<<><>>{<>}}>]<<[{{}()}{<><>}][[{}()]{[]<>)]>{[{[]<>}<{}{}>]((<> +<(<({(([{<[((<[]{}>[()[]]){((){})[(){}]})[[<[][]>{()<>}]({{}()})]]([(<<>()>{<>})<({}{})({}<>)>]((<< +<<<[<<[(<<{{(<<>()>([]()))[{(){}}{{}[]}]}{<[(){}]>{[<>[]]([]<>)}}}([<<<><>>([]<>)]]{{<()()>{{}[]}}[{< +{[<(<([([[<[{{<>{}}<{}()>}{<[]<>><<>()>}][{((){})[{}<>]}<{<>()}{<>{}}>]>{{<<[][]>[<>[]]><<()<>><[]<>>>} +[{({<[{{([[[{({}<>)[<>[])}[[[][]]({}())]]](<<<(){}>[<>]>({(){}})>[(({}()){{}{}})<<<>{}>{<>[]}>])])} +<[[<<((((<<([<()<>>{[]()}]({{}{}}<[]()>))>>{<<<{<>{}}>{(()[]){[][]}}>(({{}{}})[[<><>]{{}{} +({[({<[{{[(([{<>()}([][])](<<>{}><[]>))[{{[]<>}<<>()>><[<>()]>])]}<<{<([()<>]){{(){}}(()())} +((<{{<(<{<<({(<>{})}<[{}<>]{[]<>}>){{[<>]<<><>>}{[<>()]((){})}}>({({{}()}{()()}){[<>()]<<>{}>}}(<({}<>)([]()) +{{[<{({{[[({<([]<>)(()<>)>([{}<>]{()()})}([{{}{}}<<>[]>]{<()[]>{()()}}))]<<[{[<>()]<{}[]]}[[[]() +[((<<{(<{(([{[<>{}]({}[])}([{}[]][()<>])])[[[(<>())([]<>)]]]){<([{[]{}}[<>()]]<[<>[]][<>{}]>)(<({}{}) +((<([(<<([{(<<<>{}><<><>>>[{[]()}])[{[<>{}][[]{}]}]}([[{<>()}({}[])]<<{}>{(){}}>]{[<[]<>>[(){}]>})][<<((()() +<[<[<{({{{{({[[][]][<>[]]}<[[][]]>)[[<[]>((){})]]}<(<([]()){[][]}>[<<><>><[]<>>]]{(<<><>>)[<()[]> +{<[((<(<[({<({[]()}([]{}])<[<>{}]{{}<>}>>({<()()><<>{}>}{[<><>]<<>[]>})}{[((<>)[[]()])]})[({{[()[]]< +<{({[[{<{[<{([()[]][{}{}])}>({[<()()>(<><>)]<[()<>]([][])>}([<{}<>>(<>[])]({<>[]}(<>()))))]}(([{(([]) +<<(([[[({(<({[{}()]<()()>}<[{}{}]<[]()>>){[(<>{})[<>[]]][(()<>)(<>())]}>(<<[()()]([]{})>[[[]{}]{(){}}] +({<{<<<{<<{(<<[]{}>([]{})><{{}}[()<>]>)}[([([]{})[{}[]]]{{<><>}[()<>]})]>{{<{<<>{}>}(<[]{}>[[]])>[<<()()><() +(<<{[<{<{(<{[[{}[]]<()[]>]([()][{}[]])}(({()[]})({<><>}<{}<>>))>[[[<[][]>{(){}}]][<[(){}][{}] +[[{{({[<<([{{[<><>]{<>{}}}}])><[{[{[[][]]{()<>>}{({}<>){[]}}]({{<>{}}<[]()>})}<{[<()<>>]([()[]][()])}{{<[] +[([({<[[[[<<<[<>][<><>]><{[][]}{<>[]}>><{[[]]<<>{}>}>>[[(({}<>){{}<>})[<()[]>[()[]]]]]>{([{{<>}< +{{[<[[<<{<{({{(){}}{(){}}}({<>()}{{}{}}))((({}())({}<>))([{}()][{}<>]))}>({(({()[]}){(<><>)<{}>}](< +[({[<{{([[{([{()<>}<<>{}>]{<[]{}>})}({{[<>{})<{}()>}[[[][]]<{}[]>]})]]{<{<[<{}()>]>{{{()}(<> +{[(([[(([<[(({()}<()<>>)<(<>[])({}[])>)]>])({[([[({}<>){<>()}](<{}<>>)](<((){})[<>[]])))([<([]())({}<>)>{[{} +{([[({[[(<<(<[<>()]{{}()}>)<<(()[])>>><(((<>{})[[][]])[[[][]]{<>[]}])({<<>{}><{}[]>}<{{}[]}>)>>[{(([{} +[(([<{[<<[<{<[{}{}]{[]()}><(<>())([]{})>}{[{[]()}[{}[]]]((()<>){()()})}>{([{<>[]}([]{})]<{[][]}({}{})>){{[[]{ +[<{<[<[([{{{{<<><>>}((()()){[]()})}{{{{}<>}([]{})}([<><>]{()()])}}{{({<>{}}<{}{}>)[<<><>>({}())]}}}< +[<[[<{[((({(([<>{}]([][])){{[]()}<[][]>})[{[()<>}<()<>>}{<{}[]>}]}(<([<>{}]([]())){({}[])[<>{ +[{{<{<[<{([({([]())([]{})}{<()[]>[()<>]])(([<>{}][()[]])(<{}{}><()<>>))])}>]({(<[<(([]<>)([]<>))<[()<>](() +<({<(([[<<[[{[{}()][()<>]}((<>[])[[]])]]{{<{{}{}}{<><>}><(<>)([]{}))}({(<>{})(<>[])}{<{}<>>{<>()}})}>({{{< +(({<[([(<<(<(<<><>>)({{}()})>{{[<>()]}}){{[[()[]]{<>{}}]({[]{}})}[([()<>]{{}()}){{[]{}}(<>[])}]}>>({(<((( +<[[{([<<[[(<<([][])[<>]>[[<>[]]]>)([<(()())<()[]>><[{}][[]]>])]((<[((){})[[]()]]<({}[]>[{}[]]>> +[(<<<<({<[{<<<(){}>{[]{}}>([{}{}]({}[]))><<<[]{}>(()[])>{[{}()](()<>)}>}][<<[(<>[])<(){}>]({(){}}((){ +<[[[[{(<{([{((<>())[()<>]){<{}[]><{}()>}}][{{{<><>}[<>{}]}({{}{}}[<>{}])}[({(){}}[{}<>]){[{}[]]}] +(<<[<(<(<[[{<[<>()]<<>>>{{()<>}<[]{}>}}[(<[][]>{{}()})({()[]}(()[]))]]({((()())[{}])<<{}()){{ +{{<([{{[(({([([][]){(){}}]){[{[]<>}(()<>)]<[{}]<<>>>}}<({{{}()}[{}()]}{<(){}>{<>[]}})<<[{}()]<<>()>]({ +((<<{<{[[(<[{([]())(<><>)}](<<{}()>(()<>)>[((){})[[]{}]})>([(<[]<>><{}<>>)][<<{}()>>[({}[])([][])]]))<{(( +[[<{{<[{({{[(<<>[]>[<><>])<{[]<>}<(){}>>]<[[{}<>]<{}()>]<<[][]><<>()>>>}<[({[]()})<(<><>)<<>{} +<(({[[[<{<[(<([][])(<>{})>{{{}}[{}()]})]((<{(){}}(<>[])>([{}[]]{<>{}})){{({})}{[{}[]]}})>}{[[(((<><>}(()())) +{[[{[({{[((<(({}{})){<[][]){{}()}}>){[({{}[]}([]{}))]{[<[]{}><[]{}>]}})({[{[[]{}]{()[]}}]<(<<>>)[{{}()}<{}<> +{[[<{({([(<[[{{}[]}[()[]]][[[][]]({}{})]]<[<[]<>>[{}()]]<<<>()>[()()]>>>>{[([[()()]<<>[]>] +<([[[[{([<{{(<[]{}>[[]]){<[]()>{()<>}}}[<<[][]>((){})>{{()<>}[[]{}]}]}>[{{{<()()><(){}>}<{()()}>}{[(() +{(<{<([<[(({{[{}[]]({}[])}{{[]()}{<><>}}})[<<({}())[()[]]>{[[][]]<()[]>}>[<<()<>>([]())><[(){})<()()>>]] +{[[(<([<(((([[{}{}]{[]()}]<(<>{})<[][]>>){{<{}{}><[][]>}[{()<>}[()[]]]})<(((<>{}){[]{}})[{[]()} +{{<<<{[({{{{([(){}}[<>{}])[<(){}><{}{}>]}}[<[{<>{}}{{}{}}](<[]{}>[[][]])>]}({<{{{}{}}<{}[]>}([[]][{}<>] +({{{(<[{{<[[(({}{})<[]<>>)([{}[]]{()[]})]((<()()>)[<[]{}>{<>[]}])])<[{(<{}>[[][]])<([]())[[]()]>}< +(((<{{{(((([({()<>})<<[]<>>[<>]>])[((<<>[]>({}))[[[]()]<<><>>])(<{[][]}[{}()]><{{}[]}[()()]>) +{[<[[<{<<({(<(<>()){[]()}><([]{})[<>{}]>)[[<{}[]><[]{}>][[{}[]]<[]<>>]]})>[<{<([()<>]{{}[]})<{{}[]}<{}<>>> +((({{[(((([{<(())({}<>)>{[[]{}][[][]]}}{<<{}<>>{{}[]}>{(<><>)({}<>)}}][{{[(){}](<>{})}{<() +{{<{({({[[<{{(()[])<()[]>}}[[{{}<>}(()[])][{{}{}}{{}<>}]]>{((<{}[]>{[]<>})({[]<>}{[][]}))[([[]<>]<()()>)<<< +[[{{{{{[[{[(<[{}()]{[]()}><<()()>[(){}]>)<[[{}<>]{<>[]}]>]([(<{}<>>[[][]]){(<><>)(()[])]]<[[ +{({<[<{[<[[([[<><>][<><>]])[{{{}()}([]<>)}[[[]()][[][]]]]]<[<<()[]]{<>[]}><([])<<>()>>]{(<()<>>< +({<<<{<<{({<{[()[]]{(){}}}{((){}){{}[]}}><<{(){}}><{<>()}<{}{}>}>}<{[[[]]([]{})](<()<>>(()<>))}>)}<<[({[<> +(<<<<{[{<({{{(<><>)<()[]>}{{[]()}{()()}}}<[<[]{}>(<>[])]{[[]<>]<[]<>>}>})[((([<>]{(){}})([(){}]<<> +(([(((((<<{<[<()<>><[]()>]([()[]][<>{}])>{(((){})({}[]))(<[]{}><[]<>>)}}{(<<(){}>[{}]>{{()())<()[ +(({<([({(<{((<()()>{()[]}){<[][]>[[]<>]})[[{[]}{<><>}]<<[]><{}()>>]}(<(<[]{}><{}{}>)[(<><>){{}()}]>)> +{<<{[{[<{{{({({})<<>()>})<{[{}{}]}[[{}()]]>}}([{(({}{}}(<><>))([<>[]](<>()))}[{[{}<>]}(<<>{}>(()<>))]])}< +({[[{{{{[<{[([<>[]]{{}{}}><<<>[]>>]{[{()()}[()()]]}}((<[{}()][<>{}]>{([]()){()[]}})({[()<>](()[] +[[{{(({{({<{<<{}()>>{<<>()><{}()>}}{[{<>[]}<{}>]{<[]<>>[{}[]]}}>{[[[{}<>]({}{})]<[{}{}]<(){}}>][{({} +([[<<(<[<{{[[{(){}}<()[]>]{{()[]}}]({{[]{}}[(){}]](({}{})[[][]]))}{<[{<>[]}{{}<>}]{(<>{}){()()}}>}}<<{<( +{[<[(({[[(([[[{}()](<><>)]{{{}()}({}[])}])[<((()[])<()()>)<{<>{}}>><[{<><>}(()[])]>])](<({ +{[{<<[(<{({<[[()<>]<[]{}>][(<>){{}<>}]>}<(<<<>[]>(()())>[(()<>)[[]<>]])<[<<>{}>[<><>]]{[<>{}]{[]}}>>)[ +[{([{<([[{[([{{}<>}[{}[]]][({}{})({}{})]){({<>[]}(()()))}](<[(()[])([]{})][<()[]>{[]{}}]><{(<>())<( +([{({(((((({<({}<>)<<>[]>>{[<>[]][<><>]}}(<({}())<<>[]>>(([]<>)[<>{}])))[{({{}()}(()[])){<[]()><()( +{[{[{{<{<{<{(<()<>><()[]>)}<<<()[]><{}{}>>((<>[])<{}<>>)>><<(([]())[<>{}])({<>()}<{}>)>{([[]<> +([[(<<({{{{{[{()<>}[{}<>]]{{{}<>}<(){}>}}(([[][]][()()]))}({[{{}()}{()<>}]}<[([]<>)(<>())][(<>[] +{[<<{<<<<{<((<{}[]>[[]{}])([()<>](<>())))<{[()()]<(){}>>{<()[]>[{}{}]}>>}<[(<{{}{}}[{}{}]>)[([[] +<{{[(<(<{([{({{}[]})(<{}[]>{()<>})}]<[<<[]<>>([]<>)>{<[]{}><<>[]>}][[{()<>}[[]()]][{[]<>}(())]]>)([[[<{} +(<(<{<[({[<(<<{}<>>{{}()}>{(<>[])<()>})<{(<>())<{}()>}{[()()]<[]{}>}>><(({(){}}[[]{}]){{{} +[<[[[([{{<{[([<>]<[]()>){<()>[{}<>]}]{({[]()}[{}{}])[({}[])({}())]}}>}(<(<[[()[]]<(){}>]<<[][]>{()()}>>)(( +[<<{<<([<{<(<(<>{}){()<>}>(({}{})({}{})))<<(<>[]){[][]]>{[{}{}]{()()}}>><[[[<><>]{[]{}}](<{}< +<{<{(<<((<{{[<<>()>[()<>]]{{<>()}(<>{}))}}>({[{{[]{}}[[][]]}({(){}}[[]()])][[<<>[]>[{}<>]]{(<>[])[(){ +((({([<{[[<(({{}{}}[{}()])(([]()){{}{}})){<<[]<>>{{}()}>{{{}[]}{[]()}}}>[((<()[]>(()()))((()<>)([]{})))(( +<(<<([{[(<<<{[{}<>]{()()}}(<<>>)>([([]()){[]<>}][[()<>][<>()]])>{[<((){})[{}[]]>{((){})({}())}][([<>[]]{[] +{[({{[<{<[<(<([]<>)(<>())>[<(){}>({}[])])>]>([<{[{[]}{{}<>}][({}<>)[[]<>]]}[{(<>[])(<><>)}({()<>>{[][] +<((((<<<{<[(<[{}{}]{{}}>){({<>()}{{}{}})[[{}<>]([]())]}]([<(()[])<{}()>>][(<[]{}>(<>{}))<(()()){[]( +<[<<(({([[[<<<[]()>[()<>]>([<>()][()()])>[{(<>[])[<>]}{<{}()><[]{}}}]]]]([<{[<{}{}>{[]{}}]<<<><>>[()()]>}> +<[<{<{<({{{<<<[]<>>>((<>[])[{}()])][{<<>()><()()>}(<[][]>)]}<(<((){}){{}{}}>)>}})><{[{[{([{}{}]<[]( +({<{<{{([[{[((<>[]))]}<<<({}{})>(<[]{}>({}[]))>{[(<>())([]<>)]{{<>{}}{()<>}}}>]([<({<><>}{{}<>})[[[]<>]( +([[[([{[(<({([()[]])[{[][]}<{}<>>]}<(({}{}){()[]}){{<>[]}{(){}}}>)[<({<><>}{[]})(<(){}>(<><>))>{<[ +[{{<<{<{(<<({[()()]<()[]>})[{(<>[]){()[]}}{((){})(<>[])}]>}){<[[[[<><>]<[][]>]]<([[][]](<>[]))((<>{}) +<[((<{<(<[<[[<{}()>[[]<>]]([<>[]]<()>)]<<[<>[]]{()()}>]>([({()}((){}))]<{({}())[[]()]}(({}<>)<[]{}>)> +[{{<(<{({(<<(<()[]><{}<>>)<<<>>>><<(<>[])[{}[]]>>>({[{[]<>}]<<<>[]><{}()>>}<({{}}<()<>>)<[<>()][<><>]>>))}) +([({({{{{<(<{{<>()}({}<>)}({{}<>}<[]<>>)>)>}[{(<{[[]<>][[]{}]}[[()<>]{<>}])){(<(<>[]){<>[]}><<()>[< +{({[{{(([[<({[{}{}]})><{<<<>[]><{}[]>><{()<>}<()()>>}(<[<>()]{()()}><[{}[]]>)>]]<[[((({}())<[]()>)<<()[]>{ +[(<([{{([[<({{[]()}<(){}>}{({}<>)({}[])})>[(<{[][]}>({<>()}<[]<>>))]]{<{<<{}{}>[()[]]>[{[]<>}{()[] +([<((<<({([[([()()][()[]])[<<>{}>]]])}]>>)[<<(([[[(<<>()>)[{<><>}([][])]][((<><>)<[]{}>)[[()()]<{}{} +[[<{[[({[{{({[<>()][{}{}]}){[<()[]>][<()[]>[[]()]]}}}[[[([{}{}]{{}<>})[[{}[]]{(){}}]]]]]}{[{[<(< +[[<({[<{{<<[[({}[])][<{}<>>({}{})]]{(<<><>>{<>[]})}><<<{{}{}}{{}()}>{{<>}<<>>}]<<[()()]<[]<>>>([<>()]{[]< +<{{{([{[([{{({<><>}<[]<>>)}[({[]<>}){<{}())[<>[]]}]}{<[{{}{}}[{}{}]]>[[[()()][<>[]]]<{{}<>} +({[{{([<[<<{{<<>()><{}()>}}[[<<><>>(<>{})][{[]{}}]]><{(([]))<([]{})(<>[])>}(({<>{}}{()})(<{}{}]<<>>))>>]>[{ +<(<([{{[[([[{<[]()>[[][]]}{[{}[]]<{}{}>}]<{<<>()><{}{}>}({{}})>]<((<()<>>[{}[]])({{}}<{}()>)){([[]<>]{< +(({{(((<<{<{<{{}[]}<[]()>>[<()<>><{}<>>]}>[[(([][])<[]<>>)][[<()()><[]>]{(<><>)<()()>}]]}[<[<{()<>} +(({{{{(<[<{([{{}()}<<>{}>][<{}[]>])}[{{{[]<>}[[]]}[<(){}>]}(<{[]()}{(){}}>{([]{}){[][]}})]>]>)}[([{[[[<<()<> +(<{<[([{[(((({()}<[]()>)>))<{<[(<>[]){<>()}][(<>())(<><>)]><[<()()>][((){})<<>()>]>}{{[({}{} diff --git a/day10/part1.py b/day10/part1.py new file mode 100644 index 0000000..8514ff6 --- /dev/null +++ b/day10/part1.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +lines = (x.strip() for x in open("input.txt")) + +cnt = 0 +OPEN, CLOSE, PENALTY = "([{<", ")]}>", [3, 57, 1197, 25137] +MAP_CLOSE, MAP_PENALTY = dict(zip(OPEN, CLOSE)), dict(zip(CLOSE, PENALTY)) +for line in lines: + stack = [] + for char in line: + if char in OPEN: + stack.append(char) + elif MAP_CLOSE[stack.pop()] != char: + cnt += MAP_PENALTY[char] + break + +print(cnt) diff --git a/day10/part2.py b/day10/part2.py new file mode 100644 index 0000000..e8bd3ba --- /dev/null +++ b/day10/part2.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +from functools import reduce + +lines = (x.strip() for x in open("input.txt")) + +cnt = [] +OPEN, CLOSE, PENALTY = "([{<", ")]}>", [1, 2, 3, 4] +MAP_CLOSE, MAP_PENALTY = dict(zip(OPEN, CLOSE)), dict(zip(OPEN, PENALTY)) +for line in lines: + success = True + stack = [] + for char in line: + if char in OPEN: + stack.append(char) + elif MAP_CLOSE[stack.pop()] != char: + success = False + break + if success: + cnt.append(reduce(lambda p, c: p*5 + MAP_PENALTY[c], stack[::-1], 0)) + +cnt.sort() +print(cnt[len(cnt) // 2])