From 5e9b5d3b224614f18c3d8cd3e84a2a39bfe1a5a0 Mon Sep 17 00:00:00 2001 From: kleph Date: Fri, 10 Dec 2021 07:20:31 +0100 Subject: [PATCH] Day 10 part 1 --- 10/10.py | 34 +++++++++++++++ 10/input.txt | 102 +++++++++++++++++++++++++++++++++++++++++++ 10/input_example.txt | 10 +++++ 3 files changed, 146 insertions(+) create mode 100755 10/10.py create mode 100644 10/input.txt create mode 100644 10/input_example.txt diff --git a/10/10.py b/10/10.py new file mode 100755 index 0000000..ecda15f --- /dev/null +++ b/10/10.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# 2021 - Advent Of Code - 10 + +def parse_file(file): + with open(file) as f: + i = 0 + for line in f.readlines(): + count_open = {'(': 0, '[': 0, '{': 0, '<': 0} + chunks = [] + for c in line.strip(): + if c in close_sign.values(): # open signs + chunks.append(c) + if c in close_sign: + last_open = chunks.pop() + if close_sign[c] != last_open: + print(f'found corrupted chunk at line {i}: {line.strip()}') + count_score[c] += 1 + + +close_sign = {')': '(', ']': '[' , '}': '{', '>': '<'} +count_score = {')': 0, ']': 0, '}': 0, '>':0} +score_table = {')': 3, ']': 57, '}': 1197, '>':25137} + + +# parse_file('input_example.txt') +parse_file('input.txt') +# print_hmap(heightmap) + +print(f'char score {count_score}') +score = 0 +for c in close_sign: + score += count_score[c] * score_table[c] + +print(f'score: {score}') diff --git a/10/input.txt b/10/input.txt new file mode 100644 index 0000000..3de0014 --- /dev/null +++ b/10/input.txt @@ -0,0 +1,102 @@ +[(<[(({{<{{[{({})}{<{}{}><()<>>}]}[{[({}{})]([{}()](<>{}))}[<<[]()]>[<[]<>>{[]()}]]]}{[[[{[][]}{[]()}] +(<<{((({<(<{([()[]]<[]<>>)}>({[{<>()}]<[<>()]({}())>})){{[(<<><>>{<>()})<{[]{}}>][{[[]()]<[]()>} +{({([({[[([<{(())([][])}<(<>())[[][]]>>{{{{}{}}{<>{}}}({{}<>}<<>()>)}]<<((<><>))<<[]>((){})>>[<{{}{}} +(<[{{{[[[<[[[([]<>)]{{()()}<()()>}][({()<>}(()()))[<[][]>[[]<>]]]]([{[(){}]}(<[]{}>{{}()))]< +{(<<({<{<<[[<[[]{}]>]<[<{}{}>[{}[]]]{[<>{})({})}>]><([[{(){}}{()[]}]])>><{({<[{}()]<{}[]>>(< +<<[[<<[({[<[{{[]()}[()()]}[<{}{}>[<>]]]><[[(<>[])]]{{{{}<>}[{}()]}{<()>[{}[]]}}>](({<((){} +<{[[((<{{[[(([(){}][()<>]))[(<()()>[[]<>]){[(){}][()[]]}]]]<([<[{}{}]([]<>)><<{}<>>{{}{}}>]<({[]{}}[{}{}] +<<<{<[[[[([<([[]<>])[[<>{}][[]<>]]>{{[{}{}]}[[[]()]]}][[<((){})<[]<>>>]<{[(){}][[]<>]}<<[][]](()())>>]){<(( +[<{{({<<[{{<<(()())[{}[]]>{[<>{}]<[]<>>}>{[([]<>)[{}<>]](({}<>)[(){}])}}}[[(<{()}{<>()}>)<{<{}{}>([ +<{<[{[[<[({{[[{}[]][()()>]((<><>)[[]{}])}{({{}{}}[()])<{<>{}}(<>[])>}}<<(<<>[]>[()])>>)]({{[([<>])(<{}[]>{ +(({<{<{[[([<<{{}{}}>(<<>{}><()()>)>]{{(<{}>{{}[]})}(<([][]][<>[]]>{{<>{}}[<><>]})})(<[{{<>()}({}{})}{{{}[]}{< +{{[<<{{(({{{<{<>{}}{[]{}}>[<[]{}>{()()})}}(<({[]()}[()<>])[{<>()}<[]()>]>[[[{}[]][<>{}]]<{< +{{{<<<[(<[({([()()]))[<[()<>]{()()}>((()[])([]()))])][([<{{}()}<[]<>>>](([<>]<<>{}>){({}<>){[]<> +<<({{[([{{<[[<()()>{(){}}]{{()<>}[(){}]}]{[({}{})([]<>)]}>(<([{}()](()[]))({<>()}<<>[]>)>[<[()<>]< +{(<{{([{<{<(<({}{})([]())>)>{[{{{}[]}(<>{})}{([])<{}<>>}]<{<{}()><()[]>}<{[]{}}<[]>>>>}>}<(<<([ +([([(<{<[(<[{<<><>>(()<>)}(([]{}))][<(<>{})<{}>>{[()[]](<><>)}]>[[[{[]{}}[[]{}]]]<{[()[]]}[[{}{}]<<><>>]>]) +{<<({({{{[({[[<>[]]({}())]{[{}()]}}({[()()]{[]<>}}((()<>)<[]{}>))){[{{{}()}{{}()}}]}]}<<<[[<[]()>][ +{{[[[{<<[(([{[<>{}]<<><>>}{{<>}{[]<>}}]<[<<>[]>({}{})]>)({<{()()}>{{()[]}({}())}})}]<([{[<[][]>{()[]}]}] +(<<[<[[[<{{[{{()}[{}[]]}[<{}<>>{[]{}}]]{{[()[]]<(){}>}}}(((<{}{}>{()()}))[<{<>()}{()<>}><[ +[[{[<([([<<[[[()()]{()<>}]({<>{}}[<>[]])]>(<([<>()]<()<>>)[[{}()]]>)>])]){({{{[{<({}[]){[]()}><<[ +(<[<[(([({{[({<>[]}[<>[]])[([]{})[<>[]]]]([<{}}[{}<>]][(()()){{}()}])}([<({}())[[]<>]>([[]{}] +{([[((<(<([{([<>[]]{()})[(()[])]}])(<[<{{}()}>]>)>)>)){{{<<[<[<(<><>){<>[]}>[[<>{}]]]({<<>{}> +<<(((({<<[{([({}{})[<>()]]<<(){}>({})>)}{<<{[]{}}{<><>}><{<>{}}[()[]]>}<(([][])(<>[]))<[<>[ +{{{[{[[([({{{<{}{}>{()}}((()[]]<<>{}>)}}<[{[{}[]]<<>[]>}{[{}[]][()<>]}]<<({}[]){()()}><{<>{}}(<>[] +[[([(([({<[<([<>()][[]()])>{{<[]{}>[<>()]>[([]{})<(){}>]}]({[(()<>){{}()}]}<{(<><>)({}{})}{[[]<>]{{}()}}> +(<{([{{([<{<<<<>[]><[]()>>[(()[])[<>()]]>{({()<>}{(){}})<<{}<>>{<>{}}>}}[[{<{}()>}<(()<>)[()<>]>]{[[<> +<[[{({[<<<{{<[<>{}]({}<>)>(<()[]><[]>)}(<{{}()}<{}{}>>{{()}<[][]>})}[{({[]{}}(()[]))<[[]{}][[]{}]>}<{{<>{ +{({[[<{<([<((({}{})[{}{}])){{[()<>]<<>()>}[(<><>){[]}]}><<<<()<>>(()<>)>>[{([]){<>{}}}]>]){({{[{{} +(<<[{[<<({<{<[<>[]][{}<>]>([{}<>]<<>()>)}{(<{}{}>{{}()})<([])>}>{(({[]())(<>[])){[[]<>][<><>]} +[({(((<(<<{({<()()>({}()>}((<>[])[[]]))}>{<(<({}<>)([]())>[{()<>}<<>>])<<([])<[]()>>{(<>{})[<>{}]}>>[[ +<<{[(({<<{[{{<<>()>{<>{}}}({[]}{()})}][<[[[]()]]<<{}{}}[<>()]>>]}[<(([{}{}]<()<>>){{()<>}[[]<>]})<{<[ +(<[[{{{<<(<<[<()[]>(()[])]<[()()]([][])>><{({}<>)[<><>]}>><[(({}){[][]})((()()))]>){{<[([]<>)[<><>] +[[[[<[<[[[<(([<>{}]<<>()>)(<<>()>{{}{}}))[([()()]([]<>))]>(<[([]())<[]<>>]{<{}{}>{{}{}}}){(<()[] +{[<(<[[<{<{[{({}[])[<>{}]}<[()<>]>][(<{}<>>(()[])){{()()}<()[]>}]}[<[(()[])]({{}{}}(<>{}))>]>}<{{[{([]{})<(){ +(<[{{{{{{[{[{(<><>)({}<>)}[(()[]){<>[]}]]}[{([{}<>])}]]}((([{[[]][[]{}]}({<>()}[()[]])][({[ +(<<<<[[{{<<((<{}()>[<><>]))<[<<><>>([][])]<{{}<>}([]<>)>}>{{[(<><>){<>{}}]{<<>()>(()())}}[<[<><>]{{} +{({[[<({<{[[[[[]<>](<>{})]((<>{})<[]()>)]([<()[]>({}<>)][[[]{}>[{}()]])]{({<[][]><[]()>}<(<>{})>)((({}) +{[([[{<<[{<<[<()()>[{}[]]]>{(({}{})([]<>))[[{}()][()<>]]}>[<(([][])){[{}{}][{}{}]}>{{<(){}>([]<>)} +([{<{{{(<[{[{{[]}[()<>]}(<[]{}>{()<>})][(<[]><{}<>>)<([]{})(<>[])>]}][[{[<[]{}>][[<>[]]{<>[]}]}<((()[])( +<(({{<<[[<<[[(<>[]){[][]}]{({}())(()<>)}]{({{}<>})}><([<<>()><{}[]>][[<>{}]({}())])[(([][])({}< +[<<{{{[[[((<{([][])<<>()>}((<><>)([]{}))>))[<(<[<>()]><([][])<<><>>>)>[[<<{}{}>(<><>)><{[]{}}>}{({ +<<{<<[[[(((({{[][]}[{}[]]}(<<>{}><{}<>>))[(([]<>)<()[]>)<[<><>]>]))<<(<<<>{}>>{(<>[])})<[<< +[<<{({{<[<[<<({}[])(<><>)>(([]{})([]<>))>]>]{[(<<{(){}}[[]<>]>>){([<{}()>[()()]](([]())[<><>])) +{({<[<[{(<{[([[]<>]{<>})<{<>[]}([])>]}<{((<>[])[{}[]}){{{}{}}<[]<>>}}<{[[]{}](()[])}<(()()) +(({{<{<[[(<[([<>()][[]()])<({}<>)(()())>]{<<<>[]>{(){}}>}>([{({}())}{<[]>(())}]{<<[][]>({}[])>}))] +{{<{{(<[[[{<<<[][]><{}[]>><(())[{}[]]>>}][<(([[][]][<>{}])(<[][]>)){{([][])<{}{}>}[[[]{}]{[ +[([{<[[<[{([{<[]{}>(<>{})}]<{[[]()]}[<()<>>]>)}][([[[([])<<>()>]{<{}<>>[()<>]}}((<{}{}>(()<>))(<{} +([<{(<({((<{<{()[]]{[]<>}>(<[][]>(()<>))}{<[()[]](()())>{([][])<<>>}}>))(<[(({[]()}(()[]))([(){}]{<> +([{{[{(<[((<<[[]()](()())>{<{}()}{[]}}>{(({}<>))<<<>{}>[{}()]>})[[((<>)<[]<>>)([()()]{<>{}})]<{[(){}]{[ +<[<[<[[[({{{[[()<>]([]())]}}{({[()()]}{{<>[]}<<>{}>})[[{[]()}[{}{}]][{<>()}<{}{}>])}})<<{([{()[]}<[] +<([[<{<<{(<(<{[]}[{}()]>({()}{<>()})){{[[]()](<>[])}(<{}{}>(<><>))}><{{{(){}}<<><>>}}>){(([[()<>]<<><> +{(([(<[<{[[<{(()[])[{}<>]}<<{}()>>>([({}<>){<>{}}]([()[]]{{}()}))]({[[[][]]]})]}>][({[{<<([]<>){()<>}>({<>< +([<(((<[<({<[({}{})((){})]{{()<>}<[]<>>}>{[{()[]}<<><>>]({{}<>}[[]<>])}})[[{([[][]](()[]))({()[]})}(((( +{<[{[(([<(<{<[<>{}]>[((){})({}())]}{(<(){}>{[]<>})([()<>](()<>})}>[(<{[][]}{<>[]}>[<[]<>><< +[<<{((<(<((<<{[]<>}{[]<>}>{[<><>](()())}>{([<><>])[([]{})(<>[])]))(<<{[][]}{{}()}>[<<>{}>{{}{}}]><[({}{ +(<([((({{([[<<{}()><()[]>>[{()<>}{{}{}}]]{<({}{})[[]<>]>{(()[]){<>}}}][{{({}{})}<([]<>)<()[]>> +({([[<<[[[[([<()()>{{}<>}]({{}[]}))]<{(<(){}>[()()])}>]{{<([<><>]{[]{}})<<{}<>>[()<>]>>}{[ +<({{(<<((<<(<({}{})<{}()>>{{<>}})([[{}()]{{}()}][<<><>>])><{[<[]()>[()()]]<([]())>}>>[<<<{()}< +[[[(<((({{{{<{[][]}{<>{}}><{[]{}}<()[]>>}<([{}{}]{{}<>})>}<({[[]<>][[]<>]}[[()<>]<(){}>])>}{{( +(<<{({[{({[{(([]<>)({}[])}[<(){}>]}]})}][({(<<{(()())}[<(){}>(()[])]><({<>{}}<()()>){<[][]>[(){}]}>> +([({{{{{([{[{([][])<[][]>}<{()<>}<{}<>>>]}{[{([][])}<<()()>[{}[]]>]{<[[][]]{[]<>}>}}]<[(<<[]< +[([<({(<({[<{[{}<>]}>{[(()<>){<>()}]}](([([])[<>{}]])<[[()()]{[]}](((){}]{[]{}})>)}[<[<{<>[] +[({<[(<<{<[{[[(){}]<<><>>][<(){}>[{}[]]]}(({{}()}<[]<>>){([]()){{}()}})]><<(<<<>[]>{<>}>(({}()){<>()}))[[(< +{{{{<{{<<{[<([()[]][{}[]])[{<>{}}[(){}])><((()[]){()[]})[[{}[]](()<>)]>]}>>}}>{{[[{<(<(({}<>)[<>()]){[ +([<{[<<[{({([<(){}>([])][(()<>)<<>()>])}{[([[][]]{{}()})<[{}]({}<>]>](([[]()]<{}<>>){<{}()>[[]()]})})[< +<((<{({[<(<(<<{}<>>{[]()}><<()<>>([][])>){<<[]{}>{<>[]}>{[<>[]][()()]}}>(({{()}{()<>}}({[]<>}(<>{}))) +<[(<{{{<[(([{{[]<>}{{}()}}<[<><>]<<>[]>>]({((){})}))<(([<>()]<[][]>)(<()<>>([]<>)))>)]>[[[[[{[ +(({{(([{{((<{<<><>><{}<>}}{{{}{}}{[]()}}>[[(<>[])[{}{}]]{<()[]>[[]{}]}])){{{{{()<>}<<><>>}{<[]<>>[[]<>] +(<{(((<<(({{{{[]()}}<<()()>{[]>>}[<{<>{}}{<><>}><{{}()}({}<>)>]}))(([((<(){}>({}()))<{<><>}<[]()>>)<( +<[[<[(<<{((<[<[]()>([]<>)]{(<>[])[<>()]}>[<(()<>){[]()}>{{[]<>}([][])}])[<(([]<>){<>()})([{}()]<[]{}>)>({ +<<[[({<<({<{[({}[])<()<>>][[(){}]{[]()}]}[{<(){}>[<>[]]}{(<>[]>({}<>)}]><<([[]<>]({}))<{[]{}}(<><> +<(({([<<(({[{[[]<>]({}())}[{<><>}[[]()]]][(<{}()>)[{{}{}}[{}{}]]]}<{(<()<>>{()<>})<[()[]][{}{}]>}[[(<>[]) +[<{<({{(({(<[{(){}})(<<>()><<>()>)>)<{<({}<>)[{}[]]>(<()()>(<><>))}{([<>[]][()<>])[{[]()}{[]}]}>}))<( +[<{<[[(<([<[<<{}<>>>{[<>[]]({}())}>{[(<>{})[(){}]]{[<>[]]}}>][{<{<[]()>{{}{}}}[[[]<>]<(){}>]>([<<><>>[{}{} +<<(({[<<{<([[{[]()}{<>()}]<[[][]]>][(((){}){<>{}})([{}()]<[]<>>)])>}>([[<<(<[]<>><()()>)<[()( +{<({[{<<<{[({<()[]>}[<<>()>[(){}]])<[(<>())<[][]>](<[]()>[{}<>])>]((<(<>{}){<>{}}>{{[]()}([])})[<{{} +[<([(<[{(<([<(<>[])[()()]>{[()<>][<><>]}]<[{{}[])]((<>())[[][]])>)>({(({<><>}({}[]))<{{}<>}([]<>)>) +{<[[({<[([{<{({}()){{}{}>}>{{[()[]]}[(<>[])<{}()>]}}])[[<(([<>]<{}<>>)([{}]{<>}))<({<><>}([]<>))<[<>[]][ +{(<[[([[([{{[((){})(()<>)]}}[<(([]<>){{}{}})>{<[[]{}]{()()}>({{}()}[<>])}]][[(<[[]<>]<<><>>> +<{[<{{((<({{{[()[]]([]<>)}({{}<>}<{}()>)}(((()<>)[[]{}])[([]<>)<{}()>])]([[<()[]><<>()>]]<{{[][]}[[]]}>))>)<< +{([([<<((([(<([]<>){[][]}><{[]()}<<>{}>>)(<[<>()]([]<>)>[[[][]]<<>()>])]))(((<{<[]()><()<>>}([[]][()[]])>)<( +{<[(<<((<<({{[{}[]][<>[]]}[{{}<>}((){})]}<([()<>][{}[]])<{<>[]}({}())>>)(<[<(){}>]{{()[]}<()()>}>(<<()[]> +<(<{[({{<<{[({<>()}{<><>})(<{}{}>(<><>))]{<<{}<>>({}{})>}}[({(<>{})({}{})}{<{}{}><{}{}>})]}[<( +{<[([<(([([<(<()[]>(<>[]))[[()][<>()]]>[[{{}{}}(()())][<(){}><{}<>>]]]<((<()>((){}))<{{}{}} +((({{(({{[<[<{<>}<[]{}>>{([]{})<{}<>>}](<{<>{}}<<>()>><{(){}}[[]()]>)>({<([][]}<<>{}>><<{}()><{}{}>>} +[([{[<[[({[(<{<>[]}[{}[]]>(({}[]}{[]<>}))[<{<>{}}{<>()}>(([]<>))]][<(([])<{}()>)[<{}<>>{[]< +([<{(<[<[{([<[()[]]<()<>>>]{[{[]{}}<<>()>]}){[[[<><>][<>[]]]<({}[])<[]()>>](([[][]]<{}()>)[[<>{}]{()[]}])}}{ +[[[([{{(({<[[<<>{}>(<>())][((){})]]]{((<()<>>{[][]})((<>())(()<>))){<<<><>>(<>[])>}}}(({<([] +({{[(([<(<([<{(){}}({}())><[{}<>]>]{(<<>{}><(){}>)})>){[<[<(()()}[<>{}]>((<><>)<<>()>)][([{}{}]){(<>[])[[ +{([{((({(((([(()<>){[]()}](<{}[]>[{}{}]))<((()()){{}{}})[<[]()>]>)[((<<>[]>[()[]])(<{}<>><< +([[{[[[{<{[{{([]<>){()[]}}}]{({(()<>)({}{})}[<{}()>{[]{}}])<{[<>{}]}>}}>}]]]{<[({(<[<([]()){ +((({[<<<{{(([({}<>)<[]<>>][{{}{}}])){([[()<>]]({(){}}[<><>]))((<()()>[{}<>]){{()<>}(()[])})}}<({(( +<<<(<{(<([<{[[{}{}]]<{(){}}({}())>}[<<{}()><{}{}>><(()()){()<>}>]>]]>{<[([<<()<>>((){})>][[[()[]]<{}[]>]<(<>{ +([{<[[[[[[{(<<()<>>([][]>>)({{()[]}<[][]>}((()()){()[]}))}((([{}<>]([]<>)){<<>()>{[][]}}))]<<[[[[]()][[][]] +{<<[[{{[([<<<{()<>}>[((){}){[]{}}]><({<>[]}[{}])([[][]]({}{}))>>[(([[]<>]){<()<>>[<>{}]}){<<(){}>({}{})>[{ +<{(<(<([(<<([<[]<>>(<>{})][([]())<[][]>])([[<>()](()[])])>({(<{}<>>([][]))}[{[[][]]{(){}]}] +{[({{{[([{<((({}()){(){}})((<>[]){<>{}}))<<([][]){{}[]})[{{}{}}{{}[]}]>>}[{[[[<>[]]([]{})]<[{}()]<<><>>>](<(( +[[{[(({<[[[({((){})<()<>>}{{<>{}}[()()]}){[([]{})([]<>)][{{}}<<>()>])][{([{}<>]({}())){([]{}){ +((<[{(({<{<(((<>)<{}[]>)([<>[]]{()()}))>}>}[[<[{({[]{}}{[][]})}(<{{}[]}(()[])>(({}()){<>[]}))]<<([{}][()[]])> +<(({<[[<{{<<<[{}{}]{(){}}>{<()<>>[<>{}]}>>}[[{[([][])(()())]<[()<>]>}{<<(){}>[()[]]>([[]<>]<[][]>)}][{ +<{((<({{({<<{([]<>]{<><>}}((<>[]){<><>})>>{<{[{}{}][<>[]]}>({{<><>}[[]]}<{(){}}[<>{}]>)}})}})<((<{[(<<()( +[(({({{([([{{<[]<>>([][])}<[()<>]>}{(({}())[<>()])}]<({{{}{}}}({{}<>}<[]{}>))>)(<[[<()>((){})] diff --git a/10/input_example.txt b/10/input_example.txt new file mode 100644 index 0000000..b1518d9 --- /dev/null +++ b/10/input_example.txt @@ -0,0 +1,10 @@ +[({(<(())[]>[[{[]{<()<>> +[(()[<>])]({[<{<<[]>>( +{([(<{}[<>[]}>{[]{[(<()> +(((({<>}<{<{<>}{[]{[]{} +[[<[([]))<([[{}[[()]]] +[{[{({}]{}}([{[{{{}}([] +{<[[]]>}<{[{[{[]{()[[[] +[<(<(<(<{}))><([]([]() +<{([([[(<>()){}]>(<<{{ +<{([{{}}[<[[[<>{}]]]>[]]