Skip to content

Commit 38674a3

Browse files
committed
chore: days 16 and 17 scaffolded, test cases added
1 parent 4f4a526 commit 38674a3

File tree

12 files changed

+320
-0
lines changed

12 files changed

+320
-0
lines changed

2024/inputs/day16.txt

Lines changed: 141 additions & 0 deletions
Large diffs are not rendered by default.

2024/inputs/day17.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Register A: 30899381
2+
Register B: 0
3+
Register C: 0
4+
5+
Program: 2,4,1,1,7,5,4,0,0,3,1,6,5,5,3,0

2024/inputs/tests/test_day16_ex1.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
###############
2+
#.......#....E#
3+
#.#.###.#.###.#
4+
#.....#.#...#.#
5+
#.###.#####.#.#
6+
#.#.#.......#.#
7+
#.#.#####.###.#
8+
#...........#.#
9+
###.#.#####.#.#
10+
#...#.....#.#.#
11+
#.#.#.###.#.#.#
12+
#.....#...#.#.#
13+
#.###.#.#.#.#.#
14+
#S..#.....#...#
15+
###############

2024/inputs/tests/test_day16_ex2.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#################
2+
#...#...#...#..E#
3+
#.#.#.#.#.#.#.#.#
4+
#.#.#.#...#...#.#
5+
#.#.#.#.###.#.#.#
6+
#...#.#.#.....#.#
7+
#.#.#.#.#.#####.#
8+
#.#...#.#.#.....#
9+
#.#.#####.#.###.#
10+
#.#.#.......#...#
11+
#.#.###.#####.###
12+
#.#.#...#.....#.#
13+
#.#.#.#####.###.#
14+
#.#.#.........#.#
15+
#.#.#.#########.#
16+
#S#.............#
17+
#################

2024/inputs/tests/test_day17.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Register A: 729
2+
Register B: 0
3+
Register C: 0
4+
5+
Program: 0,1,5,4,3,0

2024/python/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ day12 = "grice_py_aoc_2024.day12.main:main"
3939
day13 = "grice_py_aoc_2024.day13.main:main"
4040
day14 = "grice_py_aoc_2024.day14.main:main"
4141
day15 = "grice_py_aoc_2024.day15.main:main"
42+
day16 = "grice_py_aoc_2024.day16.main:main"
43+
day17 = "grice_py_aoc_2024.day17.main:main"
4244

4345
[tool.pytest.ini_options]
4446
addopts = "-ra -q"

2024/python/src/grice_py_aoc_2024/day16/__init__.py

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from __future__ import annotations
2+
3+
import time
4+
from pathlib import Path
5+
6+
DIR = Path(__file__).parent
7+
FILE = DIR.parents[3] / "inputs" / f"{DIR.stem}.txt"
8+
9+
10+
def part1(contents: str) -> int:
11+
total = 0
12+
# TODO part 1
13+
return total
14+
15+
16+
def part2(contents: str) -> int:
17+
total = 0
18+
# TODO part 2
19+
return total
20+
21+
22+
def main():
23+
contents = FILE.read_text()
24+
25+
_start1 = time.perf_counter()
26+
result1 = part1(contents=contents)
27+
_delta1 = time.perf_counter() - _start1
28+
print(f">> Part 1: {result1} ({_delta1:.6f}s)")
29+
30+
_start2 = time.perf_counter()
31+
result2 = part2(contents=contents)
32+
_delta2 = time.perf_counter() - _start2
33+
print(f">> Part 2: {result2} ({_delta2:.6f}s)")
34+
35+
36+
if __name__ == "__main__":
37+
main()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
5+
import pytest
6+
7+
from .main import part1, part2
8+
9+
DIR = Path(__file__).parent
10+
TEST_FILE_EX1 = DIR.parents[3] / "inputs/tests" / f"test_{DIR.stem}_ex1.txt"
11+
TEST_FILE_EX2 = DIR.parents[3] / "inputs/tests" / f"test_{DIR.stem}_ex2.txt"
12+
EXPECTED_PART_1_EX1 = 7_036
13+
EXPECTED_PART_1_EX2 = 11_048
14+
EXPECTED_PART_2 = 456 # TODO replace!
15+
16+
17+
@pytest.mark.skip(reason=f"{DIR.stem} P1 incomplete")
18+
@pytest.mark.parametrize(
19+
"file, expected",
20+
[
21+
(TEST_FILE_EX1, EXPECTED_PART_1_EX1),
22+
(TEST_FILE_EX2, EXPECTED_PART_1_EX2),
23+
],
24+
)
25+
def test_part1(file: Path, expected: int):
26+
contents = file.read_text()
27+
result = part1(contents=contents)
28+
assert result == expected
29+
30+
31+
@pytest.mark.skip(reason=f"{DIR.stem} P2 incomplete")
32+
def test_part2():
33+
contents = TEST_FILE_EX1.read_text()
34+
result = part2(contents=contents)
35+
assert result == EXPECTED_PART_2

2024/python/src/grice_py_aoc_2024/day17/__init__.py

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from __future__ import annotations
2+
3+
import time
4+
from pathlib import Path
5+
6+
DIR = Path(__file__).parent
7+
FILE = DIR.parents[3] / "inputs" / f"{DIR.stem}.txt"
8+
9+
10+
def part1(contents: str) -> str:
11+
result = ""
12+
# TODO part 1
13+
return result
14+
15+
16+
def part2(contents: str) -> str:
17+
result = ""
18+
# TODO part 2
19+
return result
20+
21+
22+
def main():
23+
contents = FILE.read_text()
24+
25+
_start1 = time.perf_counter()
26+
result1 = part1(contents=contents)
27+
_delta1 = time.perf_counter() - _start1
28+
print(f">> Part 1: {result1} ({_delta1:.6f}s)")
29+
30+
_start2 = time.perf_counter()
31+
result2 = part2(contents=contents)
32+
_delta2 = time.perf_counter() - _start2
33+
print(f">> Part 2: {result2} ({_delta2:.6f}s)")
34+
35+
36+
if __name__ == "__main__":
37+
main()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
5+
import pytest
6+
7+
from .main import part1, part2
8+
9+
DIR = Path(__file__).parent
10+
TEST_FILE = DIR.parents[3] / "inputs/tests" / f"test_{DIR.stem}.txt"
11+
EXPECTED_PART_1 = "4,6,3,5,6,3,5,2,1,0"
12+
EXPECTED_PART_2 = "456" # TODO replace!
13+
14+
15+
@pytest.mark.skip(reason=f"{DIR.stem} P1 incomplete")
16+
def test_part1():
17+
contents = TEST_FILE.read_text()
18+
result = part1(contents=contents)
19+
assert result == EXPECTED_PART_1
20+
21+
22+
@pytest.mark.skip(reason=f"{DIR.stem} P2 incomplete")
23+
def test_part2():
24+
contents = TEST_FILE.read_text()
25+
result = part2(contents=contents)
26+
assert result == EXPECTED_PART_2

0 commit comments

Comments
 (0)