Browse Source

Adding day10 (#10)

Readding black to requirements
Adding Day 10 Part 2
Adding Day 10 Part 1

Co-authored-by: Ryan Reed <git@ryanreed.net>
Reviewed-on: https://gitea.ryanreed.net:3000/ryanreed/aoc2021/pulls/10
Co-Authored-By: Ryan Reed <ryanreed@noreply.gitea.ryanreed.net>
Co-Committed-By: Ryan Reed <ryanreed@noreply.gitea.ryanreed.net>
pull/11/head
Ryan Reed 3 years ago
parent
commit
7322cb33a1
5 changed files with 259 additions and 0 deletions
  1. +10
    -0
      inputs/day10-example.txt
  2. +102
    -0
      inputs/day10.txt
  3. +110
    -0
      puzzles/day10.py
  4. +1
    -0
      requirements.txt
  5. +36
    -0
      tests/test_day10.py

+ 10
- 0
inputs/day10-example.txt View File

@ -0,0 +1,10 @@
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
(((({<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]

+ 102
- 0
inputs/day10.txt View File

@ -0,0 +1,102 @@
[<<{[{([([({<{<>{}}>[[[]{}][[]<>])}{[(())][[<>{}]{[]{}}]})](([{<<>{}>[()<>]}<<<>()>{{}<>}>]{[{{}()}[(){}]]})
[({[[(<{[<[<{({}[])(<>{})}(([]<>)[[]()])>{[<{}()><{}{}>][<[]()>({}())]}]<(<(()<>){{}{}}>({()()}(()[])))>>[([
(<([[<(<<{((<<<>{}>{{}{}}>({()<>}{()<>}))<[(<><>)<<>()>]{((){}){[]<>}}>)}({<[(()[]){()[]}]{((
<[(<{[{{([([{{{}<>}}{{<>()}<<>>}]){[[<[]<>>(())]<<<>{}>(())>][<<{}{}>(<>())>{<{}{}><{}<>>}]}]<<({{()
{(((<{{{<<{({{()[]){()[]}}({{}}[<>[]])){[{()<>}<()()>]}}>{[[{<[]{}>{{}()}}<<()[]>[{}[]]>]{[{(){}}(()[])]<({
<(<{<<{{([[({{<>()}[(){}>}[(<>)(()[])])([[<>()]<[]()>])]{(<(<>()){[][]}>[((){}){[]{}}])[[{[]<>}({}
((<[<(([[{[{{[{}()]{<>[]}}}]{[{<()()>[{}[]]}[<[]{}>]]{{{<><>}[()[]]}<{{}{}}[<>()]>}}}[{{<{[][]}({}())><{
[([{({[({<[[<([][])<(){}>><<<><>>[[]()]>]<<({}{}))[<<>[]>]>]{[(([]<>){[]<>}){[{}{}](()())}]}>[<<{<[][
({{{(<{({((<({<>()})[(<>[])<{}()>]>{{<[]()><{}[])}[{[]{}}({}{})]})){{{[<(){}><[]<>>][<{}()>{(){}
(<[<[<{[<{{[[([]{})]](([{}{}]({}[])){<()()>({}())})}[((<{}()>{[][]}))[[<()[]><()[]>>([[]<>]([]{}))]]}({[
<{{[<[<<(<[[([[]<>]({}<>))][[({}<>){{}()}]{<(){}>(()[])}]]>{[([[[]{}][{}()]][({}{})((){})])({({}
([{{[{{[<<[([([]())<[][]>]({<>()}{[]()}))<(<<>{}>{()})>][[[{<>[]}[(){}]][[()[]]({}())]][(<[]{}
<[{<[<[<{[<([[{}()]]){<{{}<>}[{}<>]>([{}{}]<[][]>)}>][<([{(){}}<<><>>]<<[]{}>[()<>]>)><{[([](
<([[([((<[{<<<()<>><[][]>>{({}[])({}{})}>({({}<>){[]}})}<(<{[]{}}{()<>}>([(){}][()<>]))[{[{}]<{}()>}<{{}
[{{[([{{{{(({({}<>)<[][]>})([{<>()]<<>{}>]{[()()]}))({{<(){}>{<>{}}}}([<()<>>[{}{}]]{{[]{}}(()[])}))}{(((<[]
<{{{([<[{((<<<[]{}>{()[]}>{(()[])[{}()]}>[[(<><>)][[(){}]{[]<>}]])({{((){})<[][]>}[<[]()>(<>{})]}<([{}<
<[(((<{(({[{[[[]()][[]<>]]<{<><>}[()()]>}][{[[{}{}]<{}()>]<([]()){<>[])>}[(<{}<>>({}()))(<<><>>((){}
([{{[[((<{([<<()[]>{[][]}>{[[]{}]<{}()>]]{<<()<>>>{({}<>)((){})}})<[{[<>()](<>[])}]{({()}({}
(({[{(({{{<{(({}{}){[]<>})<{[][]}>}<<{{}[]}<{}}>{{()[]}{<>[]}}>>}(<<[([]{})<<>()>]<(()<>)<{}<>>>>>[{{(()[]){{
<[{<<<(([{{(<[[]()][{}[]]>[[{}()]<{}()>])<[[[]]{[][]}][(()[]}]>}}][{({<<<><>>>[<{}[]>({}{})]}<(([])<{}{}>)>)
{<(<[(({<[<{(({}){()<>}}}([[<>()](()[])])>((<[[]{}]{[]<>}>({[]<>}[[]<>])))]>}({{{[{{<>()}[(){
[{<{{{[<[[<<<[<>]>[[[][]][()<>]]>{<{(){}}<()[]>>([()[]](<>))}>[{[{<>{}}[[][]]][[[][]][<>[]])}<({{}()}{(){}}){
<<<<(([((<(([{<>()}<[]{}>]))({({{}[]}<(){}>)[(()())<{}<>>]}<{<[]()>{()[]}}([<><>]([]{}))>)>[<{<<()[]>[()<>
<{<{<((({[<{(<{}()><()[]>)<[{}()]<<>()]>}<{(<>())[[]<>]}[(<>[])[<>[]]]>>]<<<<([]{})(()())>{({}(
(<[(({[(<{(([({}{})(<><>)]<{[]}(())>)<([(){}])>)(<(((){})<<>])([{}{}][{}{}])><[<()()>[{}()]]{((
<{<(<([<{[<{[{<>()}{<>[]}]}<<[[]()]({}<>)><[[][]]([]{})>>>[[[{<>{}}(()())]({()<>}<{}{}>)]]
{[<[(<((<{<[[<[]()>[[]()]]([{}()]<<>>)]([([][])[(){}]])><{({<>[]}[[]<>])<{<>()}<()()>>}((<{}()>)<(<>[]){[]()
<{<[{((<[{([[<<><>>(()<>)](([]()){[]()})]<{(<><>){(){}}}>)}<(([{()()}<<>[]>])(<<<>{}>(()())><<{}{}><{}[]>>
(<([{<<[<({({[<>{}](<>{})}((<>{})<{}{}>))[<[()](<>())>{[[]()]<()<>>}]})[{({(()[]){[]{}}}[[[]()]
{({<(<{{[<(<([<>[]][{}{}])[[{}<>]{[][]}]>[[((){})[<>()]]({[]<>}<{}()>)]){[([[][]]<[]{}>)[[{}()]]][[([][]){[
({[<{({{(<{[{<{}[]>{<><>}}<<<>[]>([]())>](<(<><>)<[]{}>><{<>()}<()<>>>]}<{[([])<{}<>>][<[]<>>
[{<[<{<({{(((<{}[]>{[]{}}){<<>[]>[<>[]]}))<[(<<>[]>{[]{}})[<{}[]>{<>{}}]]>}{([{[<>{}]([][])}<{()()}{<><>
{[([{<([{{<[<{(){}}[()<>]><[[]][[]<>]>]([<()<>>({}<>)][<{}()>[<><>]])><<{<()()><<>()>}[[<>[]
<{({[{{([({(({[]{}}<{}{}>)({[][]}<[][]>)){{[()<>]<<><>>}{<{}{}>}}}{({[[]()](<>())}{[()[]]}>[<{()}{[]
<{<({([{{{((<{<>}<[]()>><[()()][[]<>]>)([{()<>}{<>[]}](<<>()>([]{})]))(<{<(){}>}([<>[]](()[]))>[
[{[({({<(([({{{}<>}}[<[]<>]({}{})]){({()()}{{}[]})}]{[[[()<>]<<>[]>][([][])]]})<[<<([]<>)([]{})><{<
<[[[({{{([{({<()[]>(<><>)}<{<>}([]())>)([[{}[]]<<>()>]([<>()][[]<>]))}<{<(()[])>>>]<<<{{()()}[()<>]}{([]
[<[({<<<<<<[{{{}{}}{[]<>}}[<{}{}>(<>[])]]({<<>[]><{}()>})><<<{<>()}[()<>]>[<<>[]><<>{}>]>{<{[]<>}[()
([[<<(((<[(({({}{})<[]{}>})<<<{}[]>{()<>}><{[]()}>>)((<{<>()}[<>[]]>[<{}()><{}[]}]))]{<[({(){}}
[({<(<<[{<[[<(<><>)[{}]><([][])[{}<>]>]{([<>[]]({}()))[{[]<>}([]<>)]}]>{<(<[[][]]<[]()>>{(()
{({(([({{{(<({()()}<<>()>)[(<>[])[{}{}]]>[{[()[]]([][]>}[{(){}}<{}<>>]])[(<{[][]}(<>{})>{[[]<>
(<{([(((<{[<{[<><>]{()[]}}<<[]>>><{({}<>)(<>[])}{<{}[]>[[]{})}>]({<{{}<>}(()[])>{([][])[{}
<<(<[({{[<<({{[]()}})<(([][])([]()))>){([(<>{})][<{}<>>{{}[]}])[(({}())(<><>))<<[]><<>[]>>]}>({[{{<>}(<>[])}{
[{[[<<<{(([([({}<>)[<>()]]<(<>())>){([<>][<>()]){{(){}}[<>{}]}}]([<{{}{}}<{}<>>><{<><>}>]<(<<>[]><{}[]>){[
<<{<[([{{[[[{<<>()>({}())}<<(){}>[{}()]>]](([{[]{}}[<>()]][[[]()](()[])]){[[{}()]<[]>][(<><>}]})]}[<
<[(<<(({<{((([<><>]<(){}>)<{{}}({}())>)<[<()<>>[()[]]]({[]}{[]()})>)}><<[(((()<>))<(<><>)>)]([((()<>){{}{}}
{({({<<[(<{{<{(){}}<[][]>>[[<>()]({}<>)]}}><<(<{[]<>}([][])>[<{}<>>([]())]){(<()[]>([]()))}>[({[()<>
<([({{<{([<<[[{}()]][<()[]><<>{}>]>([<{}[]><()[]>]<{{}()}[[]{}]>)>{<(<(){}>)({{}{}}{{}<>})>{([(){}][[][]])[{
<<<<(([<([[{{[{}{}]{<>[]}}[[{}{}]<[]{}>]}[({[]()}[[]<>])[[[]{}]<<>()>]]](<{<[][]}{<>()}}{{[][]}}>{
{[[<[{<{<((<<([]())({}())><(<><>)<{}<>>>)<[{{}[]}][<{}<>>([]{})]>)<{[<{}[]>(<><>)]<<(){}><[]{}>>}{<<<>{}>>
<(<<((({{[({<<{}[]>{<>[]}>{({}{}){{}[]}}}{[[()()](<>{})]{{<><>}<<>[]>}}){<[{()()}<()[]>][[{}{
[<([<<{<<[<<([()[]]({}[]))<{<>()}>>{[<()<>>[{}()]]<{()[]}{(){}>>}>]>><[([([<[]<>>{<>{}}]<([][]){<>{}}>)
[{{([{([(({<{({}[])(()())}{{{}<>}[()()]}>[[[<>[]]([][])]({<><>}<{}{}>)]}[[<{()<>}[<>()]>[<{}{}>[()()]]]{([(
<({[(([[({((<({}[])([]<>)>{<()[]>([]{})}){{([][]){[]{}}}[({}{})[{}]]})<{<{[][]}([]())><[[][]]{<><>}>}<<
[<<((<<[<{{{{<{}[]>[{}[]]}{{<>{}}{<>[]}}}[{(<>[])({}())}{<<>()>(())}]}{<{(()()){()<>}}><[([]())]<<()[]>[(
([[(<<[{[({(<<[]<>><{}>>({<>[]}([]())))[((<>[]){()()}){{[]<>}[[]()]}]}([({[]()}[[]{}])[<{}()>{[]<>}
{(<((<{([<<{{{()[]}<(){}>>[[[]()]<{}<>>]}<([[]<>]){(<>{})<()[]>}>>>{(({[<>()]([]())}))}]([<{({{
[[[[<([{[[{<[{()}(<>[])]>(<[[]{}]<{}{}>>)}]<<((<(){}>{{}[]})[([]{})[[][]]]){{<(){}><[]()>}{(()<>)[[]<>]}
<([{<<[<{{([(<<>()>(<>[]))<[<>[]]>](<({}())<()()>>)>{{{[<>[]]{<>{}}}({(){}}{{}()})}}}({{([()[]][[][]])[
<<({({{<(<(([<[]()>[{}<>]]<({}){()[]}>){[<[]{}>(()<>)]}){[{{<>{}}{()[]}}((<>[]))]{(<{}()>{(){}])[(<>{})<
(<<({(<<([(([<<><>>([][])]<[<>[]][()]>)<(<[]<>>[<>{}])>)(([({}()){[]()}]((()[])(<>()))){<<{}<>>{[]{}}>{[(
([[[{{[<{(({{(()<>){<>{}}}{[{}<>](<>[])}}{{<<><>>{{}[]}}([<><>]{<>()})}))([<([[]<>])>]({[<()[]>][
<<(([([[{({([<<><>><[]{}>][(()())(()[])])<([{}()][{}[]])<((){}){[]()}>>}<{[{[]()}[[]()]]}>)[<((<[]{}>)((<>[])
{<<{[[((<({<{<<>{}>}[(()<>)[{}[]]]>[([<>()]({}()))]}<<<<<>[]><<>>>>{(([]{})[()()])}>)((<((()[])(()<>
<{<{<{<[({(<[(<>[]){<>{}}]{(()[])([]{})}>)}<[({<<>()><{}()>})(([()<>}[[]{}])<{{}<>}>)]>)<(<{{{[]{}}<<>{}>
<[[{(<{(<([<<{{}{}}[[]<>]>><{{(){}}<()<>>}{<{}{}>{[]{}}}>])>{{<{([{}()][[][]])<([][])({}<>)>}>{
({({<<[{[[{{[{{}()}{()[]}]{[{}[]](()())}}<[([][]){()[]}]<[[]()]((){})>>}]<[(<{[]{}>{{}<>}>{
{{[<[((([<[([[()[]]{()())]<({}{}){[]{}}>)]>][<<({<(){}>({}{})}{<<>[]>[()]})<(<(){}>{[]()}){
(({[((<(<({([(()()){<>[]}]){({{}<>}{{}[]})}})[({({{}<>}[{}()]){{[]()}<<>{}>}}<<<()()>[<>{}]>{<{}{}>}>)]>[[
((<[[((<[(({[{<>()}(<>[])]}{[(()())[[][]>][<{}<>>{<><>}]})([{{<><>}({}<>)}]{(<[]<>>(()[])){<{}<
<[[{[<[<{<<<<([]{})[<><>]>(({}())(()<>))><([[]{}][[]()])<{[][]}[<>{}]>>>(({(()[]][[][]]}){{<<><>>{[][]}}}
[<[{{[{[<<{(<([][]){[]<>}><<[][]>([]<>)])<<<[]{}><<>[]>>([{}<>]<[][]>)>}>><{([({<><>}<()()>)<({
{<{([<{(((<{<{[][]}{()()}>(((){}){()()})}>)[({<<<><>){<>()}>((()[]){()[]})}{({<>()}{{}()})({<>{}
[[[(<<{({[{[[<[]<>>[{}()]][[{}[]][{}()]]][[[()<>]([][])]<<()>([]<>)>]}[({[<>]{()<>}}(<<>()><(){}>))[<({}[
<[{({<{[<[(<({{}[]}<<>()>)([{}<>]{[]{}})>)[(<{()}<()>>{[()<>][()[]]})<[[()()][{}<>]])]]<[[{(<>[]){<>()}}
<((<{[{{<{([{<()()>(()[])}{{[]<>}[[]{}]}](((<>())){{[][]}<{}[]>}))(<{((){})[<>{}]}[[<>()]<<>[]>]><{({}<>)({
{<[[<(([<[[[{{[]()}{<>{}}}<<<>[]>>][(({}{}){<>[]})[(<>{}){()<>}]]]<{<((){})([][])>}<[((){})[[]{}
([[{[[<{<((<(<<>>)>){((<{}<>>{<>()})){([{}[]}{<>()})<<{}()><<><>>>}})<{{([(){}])<<{}[]>{[]<>}>}<<<()<>>[[
<[([[[[[{((<{<(){}><<><>>}[{[]<>}[<><>]]>[({()[]}{<>[])){{{}<>}[[]{}]}])<[([[]<>][{}])([[]()][{}()])]<<{[
[{[<[<(<[([[([<>[]]<(){}>){(<><>)<{}<>>}]<[[[]()][<><>]]{{[]<>}(()[])}>]){{<{{[]{}}}((<>()){[][]})
{{([[({{(<<(<[{}[]]<<>[]>><{{}<>}{(){}}>)>>)}})((<{<{<[([][])][[<>{}]<()[]>])}<([[{}[]]{[]()}]{
<({{{{{{<(<<[<()()>([]<>)](<[]()>[<>{}])>(<{<><>}(<>[])>)>[({(<>())<<>{}>})])><<<[{[[]()]<{
{[([(<([[({<({{}[]}{{}()})<<{}<>>{<>{}}>>})([([{[][]){{}<>}]{{<>}[()[]]})((<(){}>[[]()])[[[][]]([]<>)])])]{
{(<[<{[[{({<[{<>[]}<()<>>](<{}()><{}{}>)><<({}<>)<{}()>>([<><>][{}()])>})}<[{<([()[]])>}]>](<({(<(<>())(<><
({<(({{{[[{<([[]<>])>(<{<>}>[[()()][()()]])}]]}<<[<[<<{}[]>((){})>{([]{})}]><<{<{}()>{[]()}}{{()()}<
<{<<(<[<{[<[{<{}{}>[<>{}]}[{[]<>}{<><>}]]{{<()<>>}[<{}()><{}()>]]>]}>]>)>>}<<[<(([[[<((<(){}>){([]{}
<<(<[[<[[[<<({<>{}}{()})><[([][]){[]<>}][[()[]]]>>]]{[{(<(<>{})({}{})>)}]({[({{}<>}([]<>))([()[]
<[[(({[<(<{([(()()){()[]}]<(()[]){<>()}>)<[<(){}><[]{}>]({[][]}<[]{}>)>}[<[(<>)<<>{}>)>({{<>{}}(()
([[({[<<{(<[<{{}{}}<{}{}>>{({}())(()<>)}]>[([{[]}(<>{})])])}>>]{[{[<{<(<<>{}><{}[]>)><({[]<>}<{}<>
{(<(<[<{[<{<({()[]}){({})}>}{[<[{}[]](<>())>{[{}<>](()[])}]}>]{{<[[[<><>]]](<(<>{})><{[]()}>)>}{[<{[{}{}]((
{{{(({({<[[[[[<>{}]<[]{}>][((){}){{}{}}]][[([]<>)<[]{}>]{({}())(<>[])}]][<((()<>)[()])><{[{}[]]{[][]}}{{
{<[({{([({(([<{}[]>{()[]}]){<[[][]][<>{}]>[{<>[]}({})]})}{[{[{()()}{<>()}]}{[([]{})<<><>>]}]})<<
{<<<{{({{<([<({}{})<<>{}>><[[][]]({}<>)>])>([{([{}()])}([<(){}>{{}()}](<<>{}>(<>[])))](<([<
<{{{<({[[{{<<[(){}]<[]<>>>{{{}()}([]{})}>}<<[<<>{}><{}[]>]([(){}][[]{}])><[{{}{}}<{}<>>][<[][]>
((<(<<{<(<{[[{[][]}]{{()<>}<<>{}>}](<[[]<>]<{}()>>((()())[<>{}]))}[([(<>{})<()[]>]<[[][]]<[]{}
{[<{[[{<[((<<<<>[]>[[]{}]>({{}[]>)>)<{[[[]{}]<{}{}>]<([][])(()<>)>}>)](<[[<[<>()]({}[])>]]>({{<<[]{}>{[]
<[{{[(<<([[[[<<>()><{}<>>](((){}))]([<{}{}>[<>()]](<[]()>[[]()]))][{{{<>}{[]{}}}{{{}<>}({}<>)}}[{({}{}>{{}<>}
<[<{{([{[{[((([]())({}<>)){[[]()][{}{}]})]({{(()[])[()()]}})>(({[({}())[<>()]]{<<>{}>[<>{}]}})[[{[()<>]<<>
[{([<<[<[{{<<{<>[]}({}[])>>{<{{}{}}[<><>]>([[]<>]<{}[]>)}}{[([()[]](<>))<{{}[]}<(){}>]]}}[[<{[<>[]]{[]<
<[[([<{<{<[([[()[]]])<({[]()}({}()))[(<>{}){<>[]}]>]>(([<{{}()}(()[])>{{{}<>><<>[]>}][[({}<>)[<>[]]]{{
[<((({((<<[[[{{}<>}{()<>}]]({(<>[])<()<>>}{(()()){{}{}}})]<<(({}<>))>{<<[]()>><[()()]<[]{}>>}>>>)(<<{<{<{
(<(({(<(<<([<([]<>)[{}{}>>({{}()}[{}[]])]<({[]<>}[{}{}])<([][]){{}{}}>>)>{[(<<[][]><{}()>>{{<>{

+ 110
- 0
puzzles/day10.py View File

@ -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()

+ 1
- 0
requirements.txt View File

@ -1,2 +1,3 @@
black
numpy numpy
pytest pytest

+ 36
- 0
tests/test_day10.py View File

@ -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

Loading…
Cancel
Save