diff --git a/2021/10/README.md b/2021/10/README.md new file mode 100644 index 0000000..422a559 --- /dev/null +++ b/2021/10/README.md @@ -0,0 +1,105 @@ +# 2021 Day 09: Smoke Basin +Copyright (c) Eric Wastl +#### [Direct Link](https://adventofcode.com/2021/day/10) + +You ask the submarine to determine the best route out of the deep-sea cave, but it only replies: + +``` +Syntax error in navigation subsystem on line: all of them +``` + +**All of them?!** The damage is worse than you thought. You bring up a copy of the navigation subsystem (your puzzle input). + +The navigation subsystem syntax is made of several lines containing chunks. There are one or more **chunks** on each line, and chunks contain zero or more other chunks. Adjacent chunks are not separated by any delimiter; if one chunk stops, the next chunk (if any) can immediately start. Every chunk must **open** and **close** with one of four legal pairs of matching characters: + +- If a chunk opens with `(`, it must close with `)`. +- If a chunk opens with `[`, it must close with `]`. +- If a chunk opens with `{`, it must close with `}`. +- If a chunk opens with `<`, it must close with `>`. + +So, `()` is a legal chunk that contains no other chunks, as is `[]`. More complex but valid chunks include `([])`, `{()()()}`, `<([{}])>`, `[<>({}){}[([])<>]]`, and even `(((((((((())))))))))`. + +Some lines are **incomplete**, but others are **corrupted**. Find and discard the corrupted lines first. + +A corrupted line is one where a chunk **closes with the wrong character** - that is, where the characters it opens and closes with do not form one of the four legal pairs listed above. + +Examples of corrupted chunks include `(]`, `{()()()>`, `(((()))}`, and `<([]){()}[{}])`. Such a chunk can appear anywhere within a line, and its presence causes the whole line to be considered corrupted. + +For example, consider the following navigation subsystem: + +``` +[({(<(())[]>[[{[]{<()<>> +[(()[<>])]({[<{<<[]>>( +{([(<{}[<>[]}>{[]{[(<()> +(((({<>}<{<{<>}{[]{[]{} +[[<[([]))<([[{}[[()]]] +[{[{({}]{}}([{[{{{}}([] +{<[[]]>}<{[{[{[]{()[[[] +[<(<(<(<{}))><([]([]() +<{([([[(<>()){}]>(<<{{ +<{([{{}}[<[[[<>{}]]]>[]] +``` + +Some of the lines aren't corrupted, just incomplete; you can ignore these lines for now. The remaining five lines are corrupted: + +- `{([(<{}[<>[]}>{[]{[(<()>` - Expected `]`, but found `}` instead. +- `[[<[([]))<([[{}[[()]]]` - Expected `]`, but found `)` instead. +- `[{[{({}]{}}([{[{{{}}([]` - Expected `)`, but found `]` instead. +- `[<(<(<(<{}))><([]([]()` - Expected `>`, but found `)` instead. +- `<{([([[(<>()){}]>(<<{{` - Expected `]`, but found `>` instead. + +Stop at the first incorrect closing character on each corrupted line. + +Did you know that syntax checkers actually have contests to see who can get the high score for syntax errors in a file? It's true! To calculate the syntax error score for a line, take the **first illegal character** on the line and look it up in the following table: + +- `)`: `3` points. +- `]`: `57` points. +- `}`: `1197` points. +- `>`: `25137` points. + +In the above example, an illegal `)` was found twice (`2*3 = 6` points), an illegal ] was found once (`57` points), an illegal } was found once (`1197` points), and an illegal > was found once (`25137` points). So, the total syntax error score for this file is `6+57+1197+25137` = **`26397`** points! + +Find the first illegal character in each corrupted line of the navigation subsystem. **What is the total syntax error score for those errors?** + +## Part 2 + +Now, discard the corrupted lines. The remaining lines are **incomplete**. + +Incomplete lines don't have any incorrect characters - instead, they're missing some closing characters at the end of the line. To repair the navigation subsystem, you just need to figure out **the sequence of closing characters** that complete all open chunks in the line. + +You can only use closing characters (`)`, `]`, `}`, or `>`), and you must add them in the correct order so that only legal pairs are formed and all chunks end up closed. + +In the example above, there are five incomplete lines: + +- `[({(<(())[]>[[{[]{<()<>>` - Complete by adding `}}]])})]`. +- `[(()[<>])]({[<{<<[]>>(` - Complete by adding `)}>]})`. +- `(((({<>}<{<{<>}{[]{[]{}` - Complete by adding `}}>}>))))`. +- `{<[[]]>}<{[{[{[]{()[[[]` - Complete by adding `]]}}]}]}>`. +- `<{([{{}}[<[[[<>{}]]]>[]]` - Complete by adding `])}>`. + +Did you know that autocomplete tools **also** have contests? It's true! The score is determined by considering the completion string character-by-character. Start with a total score of `0`. Then, for each character, multiply the total score by 5 and then increase the total score by the point value given for the character in the following table: + +- `)`: `1` point. +- `]`: `2` points. +- `}`: `3` points. +- `>`: `4` points. + +So, the last completion string above - `])}>` - would be scored as follows: + +- Start with a total score of `0`. +- Multiply the total score by 5 to get `0`, then add the value of `]` (2) to get a new total score of `2`. +- Multiply the total score by 5 to get `10`, then add the value of `)` (1) to get a new total score of `11`. +- Multiply the total score by 5 to get `55`, then add the value of `}` (3) to get a new total score of `58`. +- Multiply the total score by 5 to get `290`, then add the value of `>` (4) to get a new total score of `294`. + +The five lines' completion strings have total scores as follows: + +- `}}]])})]` - `288957` total points. +- `)}>]})` - `5566` total points. +- `}}>}>))))` - `1480781` total points. +- `]]}}]}]}>` - `995444` total points. +- `])}>` - `294` total points. + +Autocomplete tools are an odd bunch: the winner is found by **sorting** all of the scores and then taking the **middle** score. (There will always be an odd number of scores to consider.) In this example, the middle score is **`288957`** because there are the same number of scores smaller and larger than it. + +Find the completion string for each incomplete line, score the completion strings, and sort the scores. **What is the middle score?** diff --git a/2021/10/code.py b/2021/10/code.py new file mode 100644 index 0000000..65ac7dd --- /dev/null +++ b/2021/10/code.py @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: MIT +# Copyright (c) 2021 Akumatic +# +# https://adventofcode.com/2021/day/10 + +def read_file(filename: str = "input.txt") -> list: + with open(f"{__file__.rstrip('code.py')}{filename}", "r") as f: + return [line for line in f.read().strip().split("\n")] + +def shorten(s: str) -> str: + changes = True + while changes: + tmp = s.replace("()", "").replace("[]", "").replace("{}", "").replace("<>", "") + changes = (tmp != s) + s = tmp + return s + +def score_illegal(s: str) -> str: + points = {")": 3, "]": 57, "}": 1197, ">": 25137} + return points[[x for x in shorten(s) if x in (")", "]", "}", ">")][0]] + +def score_incomplete(s: str) -> str: + points = {"(": 1, "[": 2, "{": 3, "<": 4} + score = 0 + for c in shorten(s)[::-1]: + score *= 5 + score += points[c] + return score + +def validate(line: str) -> bool: + short = shorten(line) + return sum(short.count(c) for c in (")", "]", "}", ">")) == 0 + +def part1(vals: list) -> int: + return sum(score_illegal(line) for line in vals if not validate(line)) + +def part2(vals: list) -> int: + scores = [score_incomplete(line) for line in vals if validate(line)] + scores.sort() + return scores[len(scores) // 2] + +if __name__ == "__main__": + vals = read_file() + print(f"Part 1: {part1(vals)}") + print(f"Part 2: {part2(vals)}") diff --git a/2021/10/input.txt b/2021/10/input.txt new file mode 100644 index 0000000..46115bb --- /dev/null +++ b/2021/10/input.txt @@ -0,0 +1,94 @@ +[{{{{{<([({{<[<>()][{}()]>{<{}{}>{[]{}}}}{({{}{}][<>{}])(<<>()><{}<>>)}}<[<({}())<{}{}>>[[()[]](<>[])]]<( +(<<({{({((([[{(){}}(<><>)][{[][]}<()()>>][[[()<>]<()()>]])))}(<(<[[{()<>}]({<>{}})]><<(<()[]>[[]{}])>[{{[ +<{<{({[<{<{([<<><>>[()[]]])[<{[]<>}<<>()>>]}{{<(()<>)<(){}>>(<[]<>>)}[<[()[]]<<>{}>>[{{}{}}[<><>]]>}>({ +[[[[[(<{(<<{<({}<>)<<><>>>{<<>()><<>()>]}<[<{}{}>{<>()}]<[{}[]][{}()]>>>[<({[]}{{}[]})<{<>{ +[[{[<(<(<(({{<{}()>{{}<>}}[<()[]><<>{}>]}(<[{}[]][{}[]]><<<>{}><()<>>])))>[[(({[{}[]][{}{}]}{<<>()>[(){}] +<([[<<(([{<<{<[]><(){}>}<[{}][{}{}]>>{({{}()})[[[]()][()()]]}>}][<([[[{}{}][[]]]]<<<{}<>>{[][] +({(<{{([({[{(<{}<>><{}[]>)<<[][]>{[]{}}>}{[{{}[]}[{}{}]]{{{}[]}{(){}}}}]}>]){<<{((([<><>])([<>[]]{{}( +<{{{[{[(({<(<<{}{}>{<><>}>[{()[]}({}[])])([{()()}[<><>]](<{}()>({}())))><<(((){})[[]()])<(<>[ +{{<({<<<{<<[[{{}{}}<()[]>]]<<[<>[]]([]{})>[[[]](<>())]>>(([{<><>}])[{{{}()}(<>[])}<{[]<>}[{} +{[<([[[(<[[[{[<>()]<()[]>}]{{{{}[]}{<>{}}}[([]())]}]<[({[]{}}(<>()>){<{}{}><()<>>}][((()[])[()[]])([()()]<[ +[([([(<(({{[[((){})({}{})]]<({{}()})<<[]>[<>[]]>>}{({[()()]([][])}(([])[[]<>]))(<{{}{}}[(){} +({(<<({<<<(<[[[]()]]<[<>()]<()[]>}>[<<()()>>(<()[]>[[]])])({<<[]{}>{()[]}>({(){}}<<>[]>)}(<{(){}}<{}()> +<[((<[[{[<<[({[]<>}<<>()>)](<[<><>]>{[{}[]]<{}[]>})><<[[<>()]<[][]>]<[{}<>](<><>)>>{{[<>{} +<<<<<({[{[[[[<{}{}>]{((){}){<>[]}}][<([]{}){[]()}>[(<>())(<>[])]]]{{{<<>{}>({}())}(({}<>)[{}()])}}]({ +<[({<((<<[{(<(()()){<><>}><({}{})(<>{})>){[[()<>){{}<>}]([<>()]<[]<>>)}}<<[<{}[]>((){})][{{}[]}{() +{([({{{<[<{{{[<><>>{[]()}}}(<((){})[<>[]]>(<[]<>>{{}<>}))}[[[[()()]<{}()>][[()<>]<{}[]>]]<<<[]()><() +[{{(<[{<<{[{(<()[]>({}{}))[(<>){[]{}}]}({<<>{}>{<>()}}<<[]<>>(()())>)]((<[[]()]{{}{}}>{<<>>{<>{ +<[<{(<[({([({([]())([]())}({{}[]}{{}{}}))<{{{}{}}{{}()}}<[<>()][()()]>>]([[[{}{}][<><>]][[()<>]<{}{}>] +[[<<{{<[[{<{({<>[]}[()()])[{()[]}[[]<>]]}<({[]}((){})){[[]()]<<><>>}>>}])><<{(<{{<[]<>>(<><>)}[<<>{} +<([{[(<[<<[(({{}<>}{<><>})<{[]()}>)({{<><>><{}{}>}[([]())[{}()]])]>>[<[[[({}){[]()}][[()][ +<<<{(<(<[{([[[[]()]<()<>>](<<>[]>[{}[]])])}<[({<<>{}>([]{})})]>]<[([[({}{})(())]{({}{})}]({(()[])}<<[]{}>[( +[{(([[({[({[[{()[]}<()<>>][[{}[]](<><>)]]((<{}<>>)({{}()}<()()>))}<{[[<>{}][[]()]]<[()()]{() +{(<({<({<{((({()()}<{}[]>)(<(){}>[()()])){<{{}[]}{<>{}}>[<<>{}>[[]<>]]})<(<[<>{}]<{}<>>><[{}][()<>]>) +<{{<<({{<<((<{[]}{()<>}><([][]){<>()}>)[{(<>())[<>[]]}{<<>()>(()())}])>((({{{}<>}<()()>}[(<>{})[ +{<({({{[<<<{[({}{})<{}[]>](<[]<>>(<>[]))}>({{{<>[]}({}[])}([()<>]({}<>))})>>({<((<<><>>{[]()}) +{[[(<{[<[([<[{{}}]((()<>){{}()})>(({<><>}{{}<>})<[[]]>)]<{[([][])[{}{}]](<[]{}><{}{}>}}[(([])[[]()])]>)]{(<<< +{{((<[<<[[<(({<>}){<<><>>[[]<>]})[{{()<>}<[]{}>}([(){}]<{}{}>)]>]{<{<{()()}{{}}>[{[]<>}>}[<([]()){<>[] +<{{[{[{[(({((<()()>({}<>)){((){})[[]{}]})}([{({}[])(()[])}[[<>{}]{(){}}]>)){(<<<{}>[<>()]> +[<<<[<{<[{(<[[{}[]]([]{})]{<{}{}>{[][]}}>)[([[{}<>]{<>{}}](<{}{}>[{}]))((<<>{}>)<{()()}[[]{}]>)]}]> +(<[<([{({{(([{[]<>}({}[])])<[({}())[{}{}]]{([][])({}<>)}>)<<<[<>{}]><({}<>)<<>()>>><{{()<>}[<>()]}(<< +<{({(<<<{{{[[(<>{}){<><>}][[{}[]]]]<<(<><>){{}<>}><{<>{}}<()<>>>>}[[[((){}){{}()}][{<><>}<()()>]] +<(<({{[[[<<(({{}{}}[<>[]]))(([<><>])<[{}()]<<>{}>>)>><({<<<>>[<>[]]><({}<>)<()[]>>}{(<<><>>{()<>})})>]]{{< +(<([([(<<[[<[<[]>)(([][])[<><>])>]<[({(){}}<{}{}>)[<[][]>{()[]}]][<<<>{}>{(){}}><(()[])[[][]]>]>][{[({[]<>}<{ +{{<<<<<([<<((<{}{}>){{{}<>}<[][]]})(({{}()}<[]<>>)<<<>()>[[][]]>)>>])><(<{[{{[[]<>]<[][]>}}]}[<{( +([[<[<({(<<{<((){}][()()]>[<{}()>[<>()]]}{{[<>[]]}{{[][]}{[][]}}}>(({[<>()]{[][]}}(<[]<>>(<>())))<{<()() +[[[[<(<{{<[<([[]{}](()<>))<(<>[])[{}[]]>>{{(()<>)<{}{}>}{[()()][{}{}]}}]<[<<[]()>([]{})>{{ +{<[{<[[{{{{{((<><>)[<>[]])([<>{}]([]()))}([[{}[]](())][({}{}){{}()}])}}{((<<[]><(){}>>)<<<{}<>>{[]{}}>((()<>) +<{[<[<{{((<<<[(){}](<>)>>{<[{}{}]<[]{}>>}>)([[{[[]<>][[][]]}(<<>()>(()<>))]>{(<[(){}][<>{}]> +([({[[{([(([({[]{}}(()()))<<{})>])<<<[<><>][(){}]>({[]}{{}()})>([({}[]){(){}}][<<><>>([][])])>)(<([<<>[ +[(([[<{(<([({[[]{}]([]())}{<{}{}><[]<>>})(<<{}[]>[[]]>)][{<<[]{}>{{}<>})}([[()()][[]]]<<{}{}><{}{}>>)] +<[[(<<<<{<[{[<[]()>]<(<>[])[[]{}]>}]<<{({}<>)([]<>)}>(((<><>)(()()))<<[][]>(<>)>)>>(<{[[{}[]]<<>{}>]}> +<[<[{([<{(((([[]{}])<<<>()>[(){}]>)){<<[[]{}]{<>{}}>><[<()[]><[][]>]{[{}<>]<[][]>}>}){<{{[ +<[{<{<[<[[{{{{[][]}[{}()]}(<[]><()[]>)}<((<>()){()[]})[(<>[])]>}({[[{}[]]{[][]}]}(<<<>()>{<>[]}>[{{}[]}{<>< +<{{{<[[{<(((({[]{}}{[]{}})){[{()[]}({}{})]<<<>>(<>[])>})[(([(){}]<()<>>)({{}()}[{}{}]))<{({}[]){[]<>}}{[ +<{{([<([(({<<{<>[]}{(){}}>{({}()){{}<>}}>}<(<{<>{}}(()()>><((){})(())>)({<[]><<>>})>)[[{{[ +[{([[{<<{[(({{[][]}{{}[]}}[([]{}){()[]}]))({[[()()]][[<>()]{[]<>}]}{[({})[()<>]](<{}()]({}[]))})]}(<[< +{{[{<{[{<<<(({()[]})<<()<>>>)><{<<()()>{[]()}><({}{})<<>{}>>>{<(()())[(){}]><([]<>)[[][]]>} +<[[{{{{(<{<[[[[]()]<<>[]>][{{}{}}<[]()>]][[<{}{}>{{}<>}]{<<>{}>(())}]>{(({{}<>})[([][])<[]{}>]){{(<>{}){ +{<<{<{(([(({(<[]<>>{[]<>})[<[]<>><[]{}>]})[<({()<>}{{}{}})((()[])<{}()>)><((())){<()()>{[]}}>])([({[< +<<[<{<{<((<[{[[]<>][()()]}({<>())[<>[]])][[(<>[])[(){}]]]>{{{<[][]>}{[[][]]<{}<>>}}((((){})<()()>) +([<([[(<([([<(()()){(){}}>{(<>())<[]()>}]{({[][]})}){[<(<>())[[]{}]><[{}<>][{}{}]>){(<()>)[<<>{ +<[<(([{<[[[{<<<><>>(<>[]}>{{()}<[]()>}}{{<()>([]{})}<{<>[]}<{}[]>>}](<(<{}[]>{{}{}})[[<><>]<{}<>>]>{{<(){} +<{{<(<{<[<(<(<<>>)[<()()><<><>>]>{{<<><>>([]<>)}})(<[([][])][(<>())(<>{})]>{[(()<>)[<><>]] +[(([<<<[{{<{{{{}<>}([]<>)}<[{}[]][[]<>]>}([[[]{}][<><>]])><<[{{}}{[]<>}]<<{}[]>(()())>>[<[<><>]{<>()}>([()()] +{[{([([[[(([{<[]()>([][])}([{}()][{}<>])](<(()[])<[]()>>([[][]])))<(<<(){}><[]()>>{[{}<>]}}({(()())<[][]>} +((<(<{(<({(({([][])[[]{}]})<{<<>()>[<>()]}{[[]{}][[][]]}>){<({[][]}<{}{}>)<(<>())<{}[]>>>}}{{< +([{[<(<(({[[{({}{})[{}<>]}{{<><>}}]{(<()<>>(<>{}))}][([({}[]){<>[]}]{({})})<[{{}<>}(<>())]{(<>{})((){})}>]} +{[<<(<<[([[(<[()[]]([]())>{<<><>>{()()}})[((<>[])<()()>)<(()<>)<{}()>>]][[{[()](())}]]]{<( +(<(<<{{[[{<(({{}<>}{[]<>}){([]<>){[][]}}){(<{}()>{()})[<<>{}>]}>}({[(<<>[]>([]<>))]<[[[]<>]{[]<> +{(<<{<<[<{[{[<<>{}>([]{})]({<>[]]{()[]})}{[((){}){<>()}]{<[][]>([]<>)}}]<((<(){}>{()[]}){[< +<<({({(<[<{{(<(){}>{[]})(<<><>><()()>)}}[({([]){<>{}}}{<<>{}><()<>>})]>(([[(<>()){(){}}]([(){})(<>())) +{<[{(<([[{([<{[][]}([]{})>][([(){}])([[]<>](()[]))])[({[()<>][[]<>]}([<><>][<>[]])>]}]((<(((() +(<[[[[[({<[[<({}<>)>(({}[])[{}()])][<{{}[]}(<>{})><<[]{}>{[]{}}>]]<<[{[]()}<{}[]>]<([]())[<><>]>>>><{<(<[]<> +([[<(<[{<<<<({[]()}{()()})>><<{{<><>}<{}()>}(({}[])<<><>>)><({[]{}}{<>[]})<{[]{}}[[][]]>>>>>}(<[{([ +((((({({<{([{{{}()}({}<>)}{<{}[]><{}()>}][(<<><>><<>[]>)[{()<>}]])([[[<>{}][()()]]({<>[]}<()( +<{[({{{{<{((({()<>}<{}<>>)[<[]{}>]){[<<>[]>[(){}]]})}<([<<{}{}>>{(()()){{}()}}][<<{}[]>[(){}] +[({(([({{[{[[(()[])<[]()>]([{}[]][(){}])]{[{()[]}([]<>)]<[<>[]][<>()]>}}<(<({}())(<><>)>(<[]<>>{[]<>}))(({ +((<[<{[{<({{([<><>]<<>[]>)[[<>()]({}{})]}([{{}<>}[[]()]]{(<>{})({}<>)}]})<<{<[{}][{}]>[{[] +<(<({(([((<{([<>()]<[][]>)}<{{()<>}([][])}>>)){({[{{[]<>}(<>{})}{{()}<{}<>>}](((()<>)([][]))[{()<>}[()<>] +<([[({[[[({[[((){})(<>[])]][[((){})[{}{}]]([(){}][()<>])]})[[[(<[]<>>[{}[]])([[][]]<<>{}>)][{<[]{}>{< +(([<<[{{[<<<<{{}[]}<[]{}>>{[()<>]({}[])}>(({{}})<({}[])<()<>>>)>>]{{[(((()())<[]()>){[()<>]{<>()}}){ +[{<([<({[<([{(<><>){()()}}{<<><>>({})]])<{[<[]()>[[]<>]]({[]()}<[]()>)}[[[(){}]((){})][[{}<>]( +[[({{({([({(<{()()}(<>{})>{([]())<[]()>})[([<>[]]{{}()}){([]())[<><>]}]}{{[([][]}[[]]]{<<>( +<(<[({<<[([(<{[]<>}(<>())><([][])({}<>)>)<<{<>()}({}<>)><<{}<>>{()()}>>]({(<{}[]>([][])){< +<[<{<(<({(<[{<()[]>{{}[]}}]({[()()](()[])}{({}{})([]<>)})>({([{}[]][<>()])<<<>{}>({}<>)>}))}<[({<[( +[(<{{<{{(({<<{<>[]}([][])>><{[<>{}](<><>)}{[[]()]}>}((<({}{})<()[]>>)[<{<>[]}[{}<>]>]))({([ +[[<[{<(<([([[<()<>>{<><>}]](<<[]()><<>>>[[()[]]({}{})]))])><[((({(()[])<()<>>}[<<>{}><[][]>])<<{( +<<{{<[{({<{<[[()<>][{}()>][({}<>)({}<>)]><<(<><>)[<><>]>>}([<{[][]}({}[])><({}{})>][(<<>()>< +([[(([[<{(<{{(()()){[][]}}<{{}}[(){}]>}<{[(){}]<{}{}>}>>{{{{[]<>}(<>[])}[<(){}>([]())])[<[<> +{{(([{({((([[<[]{}>({}[])]({<>})]<[<[]()><[]<>>]({()<>](<>()))>){{[(<><>)[{}[]]][<<>{}>({}())]}(<<[][]>(<>() +({<<{<[{<[(({[<><>]}{{{}[]}[[]{}]}){{{{}[]}<<><>>][([]())(())]})[<<[[]<>]<{}{}>><<{}[]><{}[]>>>({[<>[]] +{[<({<(<[<([{{<>{}}{()<>}}([(){}]<[][]>)][(({}[]){()})([[][]]([]()))]>>]>)[<[(({[{{}[]}(()())]{<{}<>><[][]>} +[([{<{{<({<[({<>[]}{()()})(<[]{}>[()[]])]{{({}[])<()[]>}[([]<>)((){})]}>})[{<<<[{}[]][(){}] +{[[{<[<<[{<([[{}[]][{}()]]{[{}[]]{[]{}}})(({()<>}[{}()}){[[]{}]})>[{[<<>{}>]{({}<>)<{}{}>}}<{[[]<>] +[{{{<([(<[[[(<<>{}><<>[]>){([]<>){[]<>}}]({[[]<>](<><>)}({<>{}}{{}()}))]{(({{}{}}<{}[]>}<<<>>>)}] +{{<({(<(([<{{[()()]<[]<>>}}[<<[]{}>[<>()]>[(()())<<>>]]><<<{()()][<><>]>[<<><>>{()[]}]>{(<()[]> +{{<([<[[{<({{({}())<{}()>}{<{}()>[[][]]}>)<<[<<><>>{()[]}]<{[]<>}(()[])>>>>}([{[<{<>{}}({}())>((<> +[{[(<<(<[[[[({<>()}{<><>})]([<[][]><<>>])]{<({{}<>}[{}{}])[<{}<>><<><>>]>{[<<>[]><<>{}>]{[ +((((<{{(<[{{{{()[]}[()<>]}[([]())[<>{}]]}{{[()()]<()<>>}<<<>{}><[]>>}}<((<<>>)[{[][]}<<>()>])<[<[]{}>( +<[<<[<{([(<(<(()())(()())>{(()[])<{}()>})({[[]()][[][]]})><{{{{}>[{}{}]}[<{}()>[(){}]]}{{{()()}{()[ +<<<[(([([{<({<(){}>}{[()[]]{<>[]}})}{[(<[]{}>{{}()})({{}<>})]((<()[]>)<([]<>)>)}}({[{{<>()}{<>()}}(<(){}>[ +{<<(({[[<<<{(({}{}}{<>[]})[{<>()}{()[]}]}(({<>[]}[{}{}]){{(){}}[()<>]})>[[<{[][]}[<>{}]>][[<()<>><()[]>]{ +(([[<({{{({<[(()[])[[]{}]]>}[{(<[][]>[{}<>]){{[]{}}(<>()]}}({[[]()]}[<[][]>([]())])])}{{[{([{}()](< +[([<<({(([<<([[]{}]<()()>){<{}<>>[[]{}]}>[[<[]{}>(<><>)]{{(){}}[<><>]}]><({(<><>)(()())}{{(){}}((){} diff --git a/2021/10/solution.txt b/2021/10/solution.txt new file mode 100644 index 0000000..9484a3c --- /dev/null +++ b/2021/10/solution.txt @@ -0,0 +1,2 @@ +Part 1: 413733 +Part 2: 3354640192 diff --git a/2021/10/test_code.py b/2021/10/test_code.py new file mode 100644 index 0000000..26e4d7a --- /dev/null +++ b/2021/10/test_code.py @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: MIT +# Copyright (c) 2021 Akumatic + +from code import part1, part2, read_file + +def test(): + vals = read_file("test_input.txt") + assert part1(vals) == 26397 + print("Passed Part 1") + assert part2(vals) == 288957 + print("Passed Part 2") + +if __name__ == "__main__": + test() diff --git a/2021/10/test_input.txt b/2021/10/test_input.txt new file mode 100644 index 0000000..b1518d9 --- /dev/null +++ b/2021/10/test_input.txt @@ -0,0 +1,10 @@ +[({(<(())[]>[[{[]{<()<>> +[(()[<>])]({[<{<<[]>>( +{([(<{}[<>[]}>{[]{[(<()> +(((({<>}<{<{<>}{[]{[]{} +[[<[([]))<([[{}[[()]]] +[{[{({}]{}}([{[{{{}}([] +{<[[]]>}<{[{[{[]{()[[[] +[<(<(<(<{}))><([]([]() +<{([([[(<>()){}]>(<<{{ +<{([{{}}[<[[[<>{}]]]>[]] diff --git a/2021/README.md b/2021/README.md index c0a7e5c..835bbb1 100644 --- a/2021/README.md +++ b/2021/README.md @@ -24,7 +24,7 @@ Collect stars by solving puzzles. Two puzzles will be made available on each day | 07 | :white_check_mark: | :white_check_mark: | [Solution](07/code.py) | [Day 07](https://adventofcode.com/2021/day/7) | | 08 | :white_check_mark: | :white_check_mark: | [Solution](08/code.py) | [Day 08](https://adventofcode.com/2021/day/8) | | 09 | :white_check_mark: | :white_check_mark: | [Solution](09/code.py) | [Day 09](https://adventofcode.com/2021/day/9) | -| 10 | | | | | +| 10 | :white_check_mark: | :white_check_mark: | [Solution](10/code.py) | [Day 10](https://adventofcode.com/2021/day/10) | | 11 | | | | | | 12 | | | | | | 13 | | | | |