Skip to content

Commit

Permalink
chore: days 16 and 17 scaffolded, test cases added
Browse files Browse the repository at this point in the history
  • Loading branch information
GriceTurrble committed Dec 17, 2024
1 parent 4f4a526 commit 38674a3
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 0 deletions.
141 changes: 141 additions & 0 deletions 2024/inputs/day16.txt

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions 2024/inputs/day17.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Register A: 30899381
Register B: 0
Register C: 0

Program: 2,4,1,1,7,5,4,0,0,3,1,6,5,5,3,0
15 changes: 15 additions & 0 deletions 2024/inputs/tests/test_day16_ex1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
###############
#.......#....E#
#.#.###.#.###.#
#.....#.#...#.#
#.###.#####.#.#
#.#.#.......#.#
#.#.#####.###.#
#...........#.#
###.#.#####.#.#
#...#.....#.#.#
#.#.#.###.#.#.#
#.....#...#.#.#
#.###.#.#.#.#.#
#S..#.....#...#
###############
17 changes: 17 additions & 0 deletions 2024/inputs/tests/test_day16_ex2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#################
#...#...#...#..E#
#.#.#.#.#.#.#.#.#
#.#.#.#...#...#.#
#.#.#.#.###.#.#.#
#...#.#.#.....#.#
#.#.#.#.#.#####.#
#.#...#.#.#.....#
#.#.#####.#.###.#
#.#.#.......#...#
#.#.###.#####.###
#.#.#...#.....#.#
#.#.#.#####.###.#
#.#.#.........#.#
#.#.#.#########.#
#S#.............#
#################
5 changes: 5 additions & 0 deletions 2024/inputs/tests/test_day17.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Register A: 729
Register B: 0
Register C: 0

Program: 0,1,5,4,3,0
2 changes: 2 additions & 0 deletions 2024/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ day12 = "grice_py_aoc_2024.day12.main:main"
day13 = "grice_py_aoc_2024.day13.main:main"
day14 = "grice_py_aoc_2024.day14.main:main"
day15 = "grice_py_aoc_2024.day15.main:main"
day16 = "grice_py_aoc_2024.day16.main:main"
day17 = "grice_py_aoc_2024.day17.main:main"

[tool.pytest.ini_options]
addopts = "-ra -q"
Empty file.
37 changes: 37 additions & 0 deletions 2024/python/src/grice_py_aoc_2024/day16/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

import time
from pathlib import Path

DIR = Path(__file__).parent
FILE = DIR.parents[3] / "inputs" / f"{DIR.stem}.txt"


def part1(contents: str) -> int:
total = 0
# TODO part 1
return total


def part2(contents: str) -> int:
total = 0
# TODO part 2
return total


def main():
contents = FILE.read_text()

_start1 = time.perf_counter()
result1 = part1(contents=contents)
_delta1 = time.perf_counter() - _start1
print(f">> Part 1: {result1} ({_delta1:.6f}s)")

_start2 = time.perf_counter()
result2 = part2(contents=contents)
_delta2 = time.perf_counter() - _start2
print(f">> Part 2: {result2} ({_delta2:.6f}s)")


if __name__ == "__main__":
main()
35 changes: 35 additions & 0 deletions 2024/python/src/grice_py_aoc_2024/day16/test_day16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import annotations

from pathlib import Path

import pytest

from .main import part1, part2

DIR = Path(__file__).parent
TEST_FILE_EX1 = DIR.parents[3] / "inputs/tests" / f"test_{DIR.stem}_ex1.txt"
TEST_FILE_EX2 = DIR.parents[3] / "inputs/tests" / f"test_{DIR.stem}_ex2.txt"
EXPECTED_PART_1_EX1 = 7_036
EXPECTED_PART_1_EX2 = 11_048
EXPECTED_PART_2 = 456 # TODO replace!


@pytest.mark.skip(reason=f"{DIR.stem} P1 incomplete")
@pytest.mark.parametrize(
"file, expected",
[
(TEST_FILE_EX1, EXPECTED_PART_1_EX1),
(TEST_FILE_EX2, EXPECTED_PART_1_EX2),
],
)
def test_part1(file: Path, expected: int):
contents = file.read_text()
result = part1(contents=contents)
assert result == expected


@pytest.mark.skip(reason=f"{DIR.stem} P2 incomplete")
def test_part2():
contents = TEST_FILE_EX1.read_text()
result = part2(contents=contents)
assert result == EXPECTED_PART_2
Empty file.
37 changes: 37 additions & 0 deletions 2024/python/src/grice_py_aoc_2024/day17/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

import time
from pathlib import Path

DIR = Path(__file__).parent
FILE = DIR.parents[3] / "inputs" / f"{DIR.stem}.txt"


def part1(contents: str) -> str:
result = ""
# TODO part 1
return result


def part2(contents: str) -> str:
result = ""
# TODO part 2
return result


def main():
contents = FILE.read_text()

_start1 = time.perf_counter()
result1 = part1(contents=contents)
_delta1 = time.perf_counter() - _start1
print(f">> Part 1: {result1} ({_delta1:.6f}s)")

_start2 = time.perf_counter()
result2 = part2(contents=contents)
_delta2 = time.perf_counter() - _start2
print(f">> Part 2: {result2} ({_delta2:.6f}s)")


if __name__ == "__main__":
main()
26 changes: 26 additions & 0 deletions 2024/python/src/grice_py_aoc_2024/day17/test_day17.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import annotations

from pathlib import Path

import pytest

from .main import part1, part2

DIR = Path(__file__).parent
TEST_FILE = DIR.parents[3] / "inputs/tests" / f"test_{DIR.stem}.txt"
EXPECTED_PART_1 = "4,6,3,5,6,3,5,2,1,0"
EXPECTED_PART_2 = "456" # TODO replace!


@pytest.mark.skip(reason=f"{DIR.stem} P1 incomplete")
def test_part1():
contents = TEST_FILE.read_text()
result = part1(contents=contents)
assert result == EXPECTED_PART_1


@pytest.mark.skip(reason=f"{DIR.stem} P2 incomplete")
def test_part2():
contents = TEST_FILE.read_text()
result = part2(contents=contents)
assert result == EXPECTED_PART_2

0 comments on commit 38674a3

Please sign in to comment.