From 7322cb33a1e0ee16088fba66fe1e48e0c9c3d6b9 Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Fri, 10 Dec 2021 21:02:05 -0500 Subject: [PATCH] Adding day10 (#10) Readding black to requirements Adding Day 10 Part 2 Adding Day 10 Part 1 Co-authored-by: Ryan Reed Reviewed-on: https://gitea.ryanreed.net:3000/ryanreed/aoc2021/pulls/10 Co-Authored-By: Ryan Reed Co-Committed-By: Ryan Reed --- inputs/day10-example.txt | 10 ++++ inputs/day10.txt | 102 ++++++++++++++++++++++++++++++++++++ puzzles/day10.py | 110 +++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + tests/test_day10.py | 36 +++++++++++++ 5 files changed, 259 insertions(+) create mode 100644 inputs/day10-example.txt create mode 100644 inputs/day10.txt create mode 100644 puzzles/day10.py create mode 100644 tests/test_day10.py diff --git a/inputs/day10-example.txt b/inputs/day10-example.txt new file mode 100644 index 0000000..b1518d9 --- /dev/null +++ b/inputs/day10-example.txt @@ -0,0 +1,10 @@ +[({(<(())[]>[[{[]{<()<>> +[(()[<>])]({[<{<<[]>>( +{([(<{}[<>[]}>{[]{[(<()> +(((({<>}<{<{<>}{[]{[]{} +[[<[([]))<([[{}[[()]]] +[{[{({}]{}}([{[{{{}}([] +{<[[]]>}<{[{[{[]{()[[[] +[<(<(<(<{}))><([]([]() +<{([([[(<>()){}]>(<<{{ +<{([{{}}[<[[[<>{}]]]>[]] diff --git a/inputs/day10.txt b/inputs/day10.txt new file mode 100644 index 0000000..ca048fc --- /dev/null +++ b/inputs/day10.txt @@ -0,0 +1,102 @@ +[<<{[{([([({<{<>{}}>[[[]{}][[]<>])}{[(())][[<>{}]{[]{}}]})](([{<<>{}>[()<>]}<<<>()>{{}<>}>]{[{{}()}[(){}]]}) +[({[[(<{[<[<{({}[])(<>{})}(([]<>)[[]()])>{[<{}()><{}{}>][<[]()>({}())]}]<(<(()<>){{}{}}>({()()}(()[])))>>[([ +(<([[<(<<{((<<<>{}>{{}{}}>({()<>}{()<>}))<[(<><>)<<>()>]{((){}){[]<>}}>)}({<[(()[]){()[]}]{(( +<[(<{[{{([([{{{}<>}}{{<>()}<<>>}]){[[<[]<>>(())]<<<>{}>(())>][<<{}{}>(<>())>{<{}{}><{}<>>}]}]<<({{() +{(((<{{{<<{({{()[]){()[]}}({{}}[<>[]])){[{()<>}<()()>]}}>{[[{<[]{}>{{}()}}<<()[]>[{}[]]>]{[{(){}}(()[])]<({ +<(<{<<{{([[({{<>()}[(){}>}[(<>)(()[])])([[<>()]<[]()>])]{(<(<>()){[][]}>[((){}){[]{}}])[[{[]<>}({} +((<[<(([[{[{{[{}()]{<>[]}}}]{[{<()()>[{}[]]}[<[]{}>]]{{{<><>}[()[]]}<{{}{}}[<>()]>}}}[{{<{[][]}({}())><{ +[([{({[({<[[<([][])<(){}>><<<><>>[[]()]>]<<({}{}))[<<>[]>]>]{[(([]<>){[]<>}){[{}{}](()())}]}>[<<{<[][ +({{{(<{({((<({<>()})[(<>[])<{}()>]>{{<[]()><{}[])}[{[]{}}({}{})]})){{{[<(){}><[]<>>][<{}()>{(){} +(<[<[<{[<{{[[([]{})]](([{}{}]({}[])){<()()>({}())})}[((<{}()>{[][]}))[[<()[]><()[]>>([[]<>]([]{}))]]}({[ +<{{[<[<<(<[[([[]<>]({}<>))][[({}<>){{}()}]{<(){}>(()[])}]]>{[([[[]{}][{}()]][({}{})((){})])({({} +([{{[{{[<<[([([]())<[][]>]({<>()}{[]()}))<(<<>{}>{()})>][[[{<>[]}[(){}]][[()[]]({}())]][(<[]{} +<[{<[<[<{[<([[{}()]]){<{{}<>}[{}<>]>([{}{}]<[][]>)}>][<([{(){}}<<><>>]<<[]{}>[()<>]>)><{[([]( +<([[([((<[{<<<()<>><[][]>>{({}[])({}{})}>({({}<>){[]}})}<(<{[]{}}{()<>}>([(){}][()<>]))[{[{}]<{}()>}<{{} +[{{[([{{{{(({({}<>)<[][]>})([{<>()]<<>{}>]{[()()]}))({{<(){}>{<>{}}}}([<()<>>[{}{}]]{{[]{}}(()[])}))}{(((<[] +<{{{([<[{((<<<[]{}>{()[]}>{(()[])[{}()]}>[[(<><>)][[(){}]{[]<>}]])({{((){})<[][]>}[<[]()>(<>{})]}<([{}< +<[(((<{(({[{[[[]()][[]<>]]<{<><>}[()()]>}][{[[{}{}]<{}()>]<([]()){<>[])>}[(<{}<>>({}()))(<<><>>((){} +([{{[[((<{([<<()[]>{[][]}>{[[]{}]<{}()>]]{<<()<>>>{({}<>)((){})}})<[{[<>()](<>[])}]{({()}({} +(({[{(({{{<{(({}{}){[]<>})<{[][]}>}<<{{}[]}<{}}>{{()[]}{<>[]}}>>}(<<[([]{})<<>()>]<(()<>)<{}<>>>>>[{{(()[]){{ +<[{<<<(([{{(<[[]()][{}[]]>[[{}()]<{}()>])<[[[]]{[][]}][(()[]}]>}}][{({<<<><>>>[<{}[]>({}{})]}<(([])<{}{}>)>) +{<(<[(({<[<{(({}){()<>}}}([[<>()](()[])])>((<[[]{}]{[]<>}>({[]<>}[[]<>])))]>}({{{[{{<>()}[(){ +[{<{{{[<[[<<<[<>]>[[[][]][()<>]]>{<{(){}}<()[]>>([()[]](<>))}>[{[{<>{}}[[][]]][[[][]][<>[]])}<({{}()}{(){}}){ +<<<<(([((<(([{<>()}<[]{}>]))({({{}[]}<(){}>)[(()())<{}<>>]}<{<[]()>{()[]}}([<><>]([]{}))>)>[<{<<()[]>[()<> +<{<{<((({[<{(<{}()><()[]>)<[{}()]<<>()]>}<{(<>())[[]<>]}[(<>[])[<>[]]]>>]<<<<([]{})(()())>{({}( +(<[(({[(<{(([({}{})(<><>)]<{[]}(())>)<([(){}])>)(<(((){})<<>])([{}{}][{}{}])><[<()()>[{}()]]{(( +<{<(<([<{[<{[{<>()}{<>[]}]}<<[[]()]({}<>)><[[][]]([]{})>>>[[[{<>{}}(()())]({()<>}<{}{}>)]] +{[<[(<((<{<[[<[]()>[[]()]]([{}()]<<>>)]([([][])[(){}]])><{({<>[]}[[]<>])<{<>()}<()()>>}((<{}()>)<(<>[]){[]() +<{<[{((<[{([[<<><>>(()<>)](([]()){[]()})]<{(<><>){(){}}}>)}<(([{()()}<<>[]>])(<<<>{}>(()())><<{}{}><{}[]>> +(<([{<<[<({({[<>{}](<>{})}((<>{})<{}{}>))[<[()](<>())>{[[]()]<()<>>}]})[{({(()[]){[]{}}}[[[]()] +{({<(<{{[<(<([<>[]][{}{}])[[{}<>]{[][]}]>[[((){})[<>()]]({[]<>}<{}()>)]){[([[][]]<[]{}>)[[{}()]]][[([][]){[ +({[<{({{(<{[{<{}[]>{<><>}}<<<>[]>([]())>](<(<><>)<[]{}>><{<>()}<()<>>>]}<{[([])<{}<>>][<[]<>> +[{<[<{<({{(((<{}[]>{[]{}}){<<>[]>[<>[]]}))<[(<<>[]>{[]{}})[<{}[]>{<>{}}]]>}{([{[<>{}]([][])}<{()()}{<><> +{[([{<([{{<[<{(){}}[()<>]><[[]][[]<>]>]([<()<>>({}<>)][<{}()>[<><>]])><<{<()()><<>()>}[[<>[] +<{({[{{([({(({[]{}}<{}{}>)({[][]}<[][]>)){{[()<>]<<><>>}{<{}{}>}}}{({[[]()](<>())}{[()[]]}>[<{()}{[] +<{<({([{{{((<{<>}<[]()>><[()()][[]<>]>)([{()<>}{<>[]}](<<>()>([]{})]))(<{<(){}>}([<>[]](()[]))>[ +[{[({({<(([({{{}<>}}[<[]<>]({}{})]){({()()}{{}[]})}]{[[[()<>]<<>[]>][([][])]]})<[<<([]<>)([]{})><{< +<[[[({{{([{({<()[]>(<><>)}<{<>}([]())>)([[{}[]]<<>()>]([<>()][[]<>]))}<{<(()[])>>>]<<<{{()()}[()<>]}{([] +[<[({<<<<<<[{{{}{}}{[]<>}}[<{}{}>(<>[])]]({<<>[]><{}()>})><<<{<>()}[()<>]>[<<>[]><<>{}>]>{<{[]<>}[() +([[<<(((<[(({({}{})<[]{}>})<<<{}[]>{()<>}><{[]()}>>)((<{<>()}[<>[]]>[<{}()><{}[]}]))]{<[({(){}} +[({<(<<[{<[[<(<><>)[{}]><([][])[{}<>]>]{([<>[]]({}()))[{[]<>}([]<>)]}]>{<(<[[][]]<[]()>>{(() +{({(([({{{(<({()()}<<>()>)[(<>[])[{}{}]]>[{[()[]]([][]>}[{(){}}<{}<>>]])[(<{[][]}(<>{})>{[[]<> +(<{([(((<{[<{[<><>]{()[]}}<<[]>>><{({}<>)(<>[])}{<{}[]>[[]{})}>]({<{{}<>}(()[])>{([][])[{} +<<(<[({{[<<({{[]()}})<(([][])([]()))>){([(<>{})][<{}<>>{{}[]}])[(({}())(<><>))<<[]><<>[]>>]}>({[{{<>}(<>[])}{ +[{[[<<<{(([([({}<>)[<>()]]<(<>())>){([<>][<>()]){{(){}}[<>{}]}}]([<{{}{}}<{}<>>><{<><>}>]<(<<>[]><{}[]>){[ +<<{<[([{{[[[{<<>()>({}())}<<(){}>[{}()]>]](([{[]{}}[<>()]][[[]()](()[])]){[[{}()]<[]>][(<><>}]})]}[< +<[(<<(({<{((([<><>]<(){}>)<{{}}({}())>)<[<()<>>[()[]]]({[]}{[]()})>)}><<[(((()<>))<(<><>)>)]([((()<>){{}{}} +{({({<<[(<{{<{(){}}<[][]>>[[<>()]({}<>)]}}><<(<{[]<>}([][])>[<{}<>>([]())]){(<()[]>([]()))}>[({[()<> +<([({{<{([<<[[{}()]][<()[]><<>{}>]>([<{}[]><()[]>]<{{}()}[[]{}]>)>{<(<(){}>)({{}{}}{{}<>})>{([(){}][[][]])[{ +<<<<(([<([[{{[{}{}]{<>[]}}[[{}{}]<[]{}>]}[({[]()}[[]<>])[[[]{}]<<>()>]]](<{<[][]}{<>()}}{{[][]}}>{ +{[[<[{<{<((<<([]())({}())><(<><>)<{}<>>>)<[{{}[]}][<{}<>>([]{})]>)<{[<{}[]>(<><>)]<<(){}><[]{}>>}{<<<>{}>> +<(<<((({{[({<<{}[]>{<>[]}>{({}{}){{}[]}}}{[[()()](<>{})]{{<><>}<<>[]>}}){<[{()()}<()[]>][[{}{ +[<([<<{<<[<<([()[]]({}[]))<{<>()}>>{[<()<>>[{}()]]<{()[]}{(){}>>}>]>><[([([<[]<>>{<>{}}]<([][]){<>{}}>) +[{{([{([(({<{({}[])(()())}{{{}<>}[()()]}>[[[<>[]]([][])]({<><>}<{}{}>)]}[[<{()<>}[<>()]>[<{}{}>[()()]]]{([( +<({[(([[({((<({}[])([]<>)>{<()[]>([]{})}){{([][]){[]{}}}[({}{})[{}]]})<{<{[][]}([]())><[[][]]{<><>}>}<< +[<<((<<[<{{{{<{}[]>[{}[]]}{{<>{}}{<>[]}}}[{(<>[])({}())}{<<>()>(())}]}{<{(()()){()<>}}><[([]())]<<()[]>[( +([[(<<[{[({(<<[]<>><{}>>({<>[]}([]())))[((<>[]){()()}){{[]<>}[[]()]}]}([({[]()}[[]{}])[<{}()>{[]<>} +{(<((<{([<<{{{()[]}<(){}>>[[[]()]<{}<>>]}<([[]<>]){(<>{})<()[]>}>>>{(({[<>()]([]())}))}]([<{({{ +[[[[<([{[[{<[{()}(<>[])]>(<[[]{}]<{}{}>>)}]<<((<(){}>{{}[]})[([]{})[[][]]]){{<(){}><[]()>}{(()<>)[[]<>]} +<([{<<[<{{([(<<>()>(<>[]))<[<>[]]>](<({}())<()()>>)>{{{[<>[]]{<>{}}}({(){}}{{}()})}}}({{([()[]][[][]])[ +<<({({{<(<(([<[]()>[{}<>]]<({}){()[]}>){[<[]{}>(()<>)]}){[{{<>{}}{()[]}}((<>[]))]{(<{}()>{(){}])[(<>{})< +(<<({(<<([(([<<><>>([][])]<[<>[]][()]>)<(<[]<>>[<>{}])>)(([({}()){[]()}]((()[])(<>()))){<<{}<>>{[]{}}>{[( +([[[{{[<{(({{(()<>){<>{}}}{[{}<>](<>[])}}{{<<><>>{{}[]}}([<><>]{<>()})}))([<([[]<>])>]({[<()[]>][ +<<(([([[{({([<<><>><[]{}>][(()())(()[])])<([{}()][{}[]])<((){}){[]()}>>}<{[{[]()}[[]()]]}>)[<((<[]{}>)((<>[]) +{<<{[[((<({<{<<>{}>}[(()<>)[{}[]]]>[([<>()]({}()))]}<<<<<>[]><<>>>>{(([]{})[()()])}>)((<((()[])(()<> +<{<{<{<[({(<[(<>[]){<>{}}]{(()[])([]{})}>)}<[({<<>()><{}()>})(([()<>}[[]{}])<{{}<>}>)]>)<(<{{{[]{}}<<>{}> +<[[{(<{(<([<<{{}{}}[[]<>]>><{{(){}}<()<>>}{<{}{}>{[]{}}}>])>{{<{([{}()][[][]])<([][])({}<>)>}>{ +({({<<[{[[{{[{{}()}{()[]}]{[{}[]](()())}}<[([][]){()[]}]<[[]()]((){})>>}]<[(<{[]{}>{{}<>}>{ +{{[<[((([<[([[()[]]{()())]<({}{}){[]{}}>)]>][<<({<(){}>({}{})}{<<>[]>[()]})<(<(){}>{[]()}){ +(({[((<(<({([(()()){<>[]}]){({{}<>}{{}[]})}})[({({{}<>}[{}()]){{[]()}<<>{}>}}<<<()()>[<>{}]>{<{}{}>}>)]>[[ +((<[[((<[(({[{<>()}(<>[])]}{[(()())[[][]>][<{}<>>{<><>}]})([{{<><>}({}<>)}]{(<[]<>>(()[])){<{}< +<[[{[<[<{<<<<([]{})[<><>]>(({}())(()<>))><([[]{}][[]()])<{[][]}[<>{}]>>>(({(()[]][[][]]}){{<<><>>{[][]}}} +[<[{{[{[<<{(<([][]){[]<>}><<[][]>([]<>)])<<<[]{}><<>[]>>([{}<>]<[][]>)>}>><{([({<><>}<()()>)<({ +{<{([<{(((<{<{[][]}{()()}>(((){}){()()})}>)[({<<<><>){<>()}>((()[]){()[]})}{({<>()}{{}()})({<>{} +[[[(<<{({[{[[<[]<>>[{}()]][[{}[]][{}()]]][[[()<>]([][])]<<()>([]<>)>]}[({[<>]{()<>}}(<<>()><(){}>))[<({}[ +<[{({<{[<[(<({{}[]}<<>()>)([{}<>]{[]{}})>)[(<{()}<()>>{[()<>][()[]]})<[[()()][{}<>]])]]<[[{(<>[]){<>()}} +<((<{[{{<{([{<()()>(()[])}{{[]<>}[[]{}]}](((<>())){{[][]}<{}[]>}))(<{((){})[<>{}]}[[<>()]<<>[]>]><{({}<>)({ +{<[[<(([<[[[{{[]()}{<>{}}}<<<>[]>>][(({}{}){<>[]})[(<>{}){()<>}]]]<{<((){})([][])>}<[((){})[[]{} +([[{[[<{<((<(<<>>)>){((<{}<>>{<>()})){([{}[]}{<>()})<<{}()><<><>>>}})<{{([(){}])<<{}[]>{[]<>}>}<<<()<>>[[ +<[([[[[[{((<{<(){}><<><>>}[{[]<>}[<><>]]>[({()[]}{<>[])){{{}<>}[[]{}]}])<[([[]<>][{}])([[]()][{}()])]<<{[ +[{[<[<(<[([[([<>[]]<(){}>){(<><>)<{}<>>}]<[[[]()][<><>]]{{[]<>}(()[])}>]){{<{{[]{}}}((<>()){[][]}) +{{([[({{(<<(<[{}[]]<<>[]>><{{}<>}{(){}}>)>>)}})((<{<{<[([][])][[<>{}]<()[]>])}<([[{}[]]{[]()}]{ +<({{{{{{<(<<[<()()>([]<>)](<[]()>[<>{}])>(<{<><>}(<>[])>)>[({(<>())<<>{}>})])><<<[{[[]()]<{ +{[([(<([[({<({{}[]}{{}()})<<{}<>>{<>{}}>>})([([{[][]){{}<>}]{{<>}[()[]]})((<(){}>[[]()])[[[][]]([]<>)])])]{ +{(<[<{[[{({<[{<>[]}<()<>>](<{}()><{}{}>)><<({}<>)<{}()>>([<><>][{}()])>})}<[{<([()[]])>}]>](<({(<(<>())(<>< +({<(({{{[[{<([[]<>])>(<{<>}>[[()()][()()]])}]]}<<[<[<<{}[]>((){})>{([]{})}]><<{<{}()>{[]()}}{{()()}< +<{<<(<[<{[<[{<{}{}>[<>{}]}[{[]<>}{<><>}]]{{<()<>>}[<{}()><{}()>]]>]}>]>)>>}<<[<(([[[<((<(){}>){([]{} +<<(<[[<[[[<<({<>{}}{()})><[([][]){[]<>}][[()[]]]>>]]{[{(<(<>{})({}{})>)}]({[({{}<>}([]<>))([()[] +<[[(({[<(<{([(()()){()[]}]<(()[]){<>()}>)<[<(){}><[]{}>]({[][]}<[]{}>)>}[<[(<>)<<>{}>)>({{<>{}}(() +([[({[<<{(<[<{{}{}}<{}{}>>{({}())(()<>)}]>[([{[]}(<>{})])])}>>]{[{[<{<(<<>{}><{}[]>)><({[]<>}<{}<> +{(<(<[<{[<{<({()[]}){({})}>}{[<[{}[]](<>())>{[{}<>](()[])}]}>]{{<[[[<><>]]](<(<>{})><{[]()}>)>}{[<{[{}{}](( +{{{(({({<[[[[[<>{}]<[]{}>][((){}){{}{}}]][[([]<>)<[]{}>]{({}())(<>[])}]][<((()<>)[()])><{[{}[]]{[][]}}{{ +{<[({{([({(([<{}[]>{()[]}]){<[[][]][<>{}]>[{<>[]}({})]})}{[{[{()()}{<>()}]}{[([]{})<<><>>]}]})<< +{<<<{{({{<([<({}{})<<>{}>><[[][]]({}<>)>])>([{([{}()])}([<(){}>{{}()}](<<>{}>(<>[])))](<([< +<{{{<({[[{{<<[(){}]<[]<>>>{{{}()}([]{})}>}<<[<<>{}><{}[]>]([(){}][[]{}])><[{{}{}}<{}<>>][<[][]> +((<(<<{<(<{[[{[][]}]{{()<>}<<>{}>}](<[[]<>]<{}()>>((()())[<>{}]))}[([(<>{})<()[]>]<[[][]]<[]{} +{[<{[[{<[((<<<<>[]>[[]{}]>({{}[]>)>)<{[[[]{}]<{}{}>]<([][])(()<>)>}>)](<[[<[<>()]({}[])>]]>({{<<[]{}>{[] +<[{{[(<<([[[[<<>()><{}<>>](((){}))]([<{}{}>[<>()]](<[]()>[[]()]))][{{{<>}{[]{}}}{{{}<>}({}<>)}}[{({}{}>{{}<>} +<[<{{([{[{[((([]())({}<>)){[[]()][{}{}]})]({{(()[])[()()]}})>(({[({}())[<>()]]{<<>{}>[<>{}]}})[[{[()<>]<<> +[{([<<[<[{{<<{<>[]}({}[])>>{<{{}{}}[<><>]>([[]<>]<{}[]>)}}{[([()[]](<>))<{{}[]}<(){}>]]}}[[<{[<>[]]{[]< +<[[([<{<{<[([[()[]]])<({[]()}({}()))[(<>{}){<>[]}]>]>(([<{{}()}(()[])>{{{}<>><<>[]>}][[({}<>)[<>[]]]{{ +[<((({((<<[[[{{}<>}{()<>}]]({(<>[])<()<>>}{(()()){{}{}}})]<<(({}<>))>{<<[]()>><[()()]<[]{}>>}>>>)(<<{<{<{ +(<(({(<(<<([<([]<>)[{}{}>>({{}()}[{}[]])]<({[]<>}[{}{}])<([][]){{}{}}>>)>{[(<<[][]><{}()>>{{<>{ diff --git a/puzzles/day10.py b/puzzles/day10.py new file mode 100644 index 0000000..85dc4af --- /dev/null +++ b/puzzles/day10.py @@ -0,0 +1,110 @@ +""" +Advent of Code 2021 - Day 10 + +Run with: + python puzzles/day10.py inputs/day10.txt +""" + +import pathlib +import sys +from typing import Dict, List, Tuple + +from statistics import median + + +class Subsystem: + nav_data = None + open_chars = ["(", "[", "{", "<"] + close_chars = [")", "]", "}", ">"] + + def __init__(self, inputs: List[str]) -> None: + self.nav_data = inputs + self.validate() + + def validate(self) -> None: + chunks = {"corrupted": [], "incomplete": [], "complete": []} + corrupted_chars = [] + incomplete_chunks = [] + + for line in self.nav_data: + corrupted = False + + opens = [] + for char in line: + if char in self.open_chars: + opens.append(char) + continue + + open_char = self.open_chars[self.close_chars.index(char)] + if opens[-1] != open_char: + corrupted = True + corrupted_chars.append(char) + break + + del opens[-1] # Clear the open bracket + + if corrupted: + chunks["corrupted"].append(line) + elif len(opens) != 0: + chunks["incomplete"].append(line) + incomplete_chunks.append(opens) + else: + chunks["complete"].append(line) + + self.chunks = chunks + self.corrupted_chars = corrupted_chars + self.incomplete_chunks = incomplete_chunks + + def score_corrupted(self) -> int: + scores = {")": 3, "]": 57, "}": 1197, ">": 25137,} + return sum([scores[char] for char in self.corrupted_chars]) + + def score_incomplete(self) -> int: + scores = {")": 1, "]": 2, "}": 3, ">": 4,} + total_scores = [] + for chunk in self.incomplete_chunks: + total_score = 0 + for char in reversed(chunk): + close_char = self.close_chars[self.open_chars.index(char)] + total_score = total_score * 5 + scores[close_char] + total_scores.append(total_score) + + return median(total_scores) + + +def part1(inputs: List[int]) -> int: + s = Subsystem(inputs) + return s.score_corrupted() + + +def part2(inputs: List[int]) -> int: + s = Subsystem(inputs) + return s.score_incomplete() + + +def parse(inputs: str) -> List[int]: + """Parse the input string""" + return inputs.split() + + +def solve(path: str) -> Tuple[int, int]: + """Solve the puzzle""" + puzzle_input = parse(pathlib.Path(path).read_text().strip()) + part1_result = part1(puzzle_input) + part2_result = part2(puzzle_input) + + return part1_result, part2_result + + +def main() -> None: + for path in sys.argv[1:]: + print(f"Input File: {path}") + + part1_result, part2_result = solve(path) + + print(f"Part 1 Result: {part1_result}") + print(f"Part 2 Result: {part2_result}") + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt index 1cc18fc..3481db4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ +black numpy pytest diff --git a/tests/test_day10.py b/tests/test_day10.py new file mode 100644 index 0000000..81acba1 --- /dev/null +++ b/tests/test_day10.py @@ -0,0 +1,36 @@ +import pathlib +import pytest +import sys + +ROOT_DIR = pathlib.Path(__file__).parent.parent +sys.path.append(f"{ROOT_DIR}/puzzles") +import day10 as aoc + +INPUTS_DIR = f"{ROOT_DIR}/inputs" + +@pytest.fixture +def example_data(): + input_path = f"{INPUTS_DIR}/day10-example.txt" + return aoc.parse(pathlib.Path(input_path).read_text().strip()) + + +@pytest.fixture +def day10_data(): + input_path = f"{INPUTS_DIR}/day10.txt" + return aoc.parse(pathlib.Path(input_path).read_text().strip()) + + +def test_example1(example_data): + assert aoc.part1(example_data) == 26397 + + +def test_example2(example_data): + assert aoc.part2(example_data) == 288957 + + +def test_part1(day10_data): + assert aoc.part1(day10_data) == 387363 + + +def test_part2(day10_data): + assert aoc.part2(day10_data) == 4330777059