Skip to content

Commit 9c8dd0a

Browse files
committed
🎉 D4P1 Complete!
1 parent e3c09f4 commit 9c8dd0a

File tree

1 file changed

+58
-7
lines changed

1 file changed

+58
-7
lines changed

aoc_25/solutions/day04.py

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,76 @@
11
"""Day 4 - Title Goes Here"""
22

33
from typing import Any
4-
from utils.aoc_utils import input_for_day, report_results, AoCResult
4+
from utils.aoc_utils import report_results, AoCResult, input_for_day
55

6+
LooRollGrid = list[list[str]]
67

7-
EXAMPLE: list = []
8-
DATA = input_for_day(4)
8+
ORIGINAL_EXAMPLE: str = """..@@.@@@@.
9+
@@@.@.@.@@
10+
@@@@@.@.@@
11+
@.@@@@..@.
12+
@@.@@@@.@@
13+
.@@@@@@@.@
14+
.@.@.@.@@@
15+
@.@@@.@@@@
16+
.@@@@@@@@.
17+
@.@.@@@.@."""
918

19+
EXAMPLE: LooRollGrid = [list(x) for x in ORIGINAL_EXAMPLE.splitlines()]
20+
INPUT_DATA: list[str] = input_for_day(4, 2025, ff="lines")
21+
DATA: LooRollGrid = [list(x) for x in INPUT_DATA]
1022

11-
def helperfunction(data: Any) -> None:
12-
return None
23+
24+
def parse_loogrid_p1(data: LooRollGrid) -> int:
25+
"""Navigate through the Loo Roll Grid for AOCD4P1.
26+
27+
Insert an extra layer of blank padding, slide a
28+
3x3 window and count adjacent loo rolls.
29+
If less than 4 adjacent loo rolls, count it!
30+
31+
Args:
32+
data (LooRollGrid): List of lists, @ = loo roll.
33+
34+
Returns:
35+
int: Count of valid positions.
36+
"""
37+
forklift_access: int = 0
38+
# add an extra padding 0 and -1
39+
for row in data:
40+
row.insert(0, ".")
41+
row.insert(len(data[0]), ".")
42+
43+
# add an extra layer of padding...
44+
data.insert(0, list("." * len(data[0])))
45+
data.insert(len(data), list("." * len(data[0])))
46+
47+
# trundle through the grid
48+
for row_idx, row in enumerate(data[1:-1], 1):
49+
# print(ri, row[1:-1])
50+
for col_idx, col in enumerate(row[1:-1], 1):
51+
if "@" in col:
52+
# grab a 3x3 window
53+
window: LooRollGrid = [
54+
row[col_idx - 1:col_idx + 2]
55+
for row in data[row_idx - 1:row_idx + 2]
56+
]
57+
# smoosh it together
58+
join_window: str = "".join("".join(row) for row in window)
59+
# deduct the initial @
60+
num_rolls: int = join_window.count("@") - 1
61+
if num_rolls < 4:
62+
forklift_access += 1
63+
return forklift_access
1364

1465

1566
@report_results
1667
def solveday(data: Any) -> AoCResult:
17-
p1: int = 0
68+
p1: int = parse_loogrid_p1(data)
1869
p2: int = 0
1970
return p1, p2
2071

2172

22-
expected_test_results: AoCResult = (0, 0)
73+
expected_test_results: AoCResult = (13, 0)
2374

2475

2576
def tests(test_input: Any) -> None:

0 commit comments

Comments
 (0)