Skip to content

Commit 831dd55

Browse files
committed
Add methods that returns whether given position and digits are adjacent
1 parent 94cdc82 commit 831dd55

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

puzzles/solutions/2023/d03/schematic_parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,13 @@ def find_gears(self):
8484
):
8585
if self._schematic[row][column] == "*":
8686
self._gears_positions.append((row, column))
87+
88+
@staticmethod
89+
def _is_number_adjacent(
90+
position: tuple[int, int], digits_positions: Iterable[tuple[int, int]]
91+
) -> bool:
92+
position_row, position_column = position
93+
return any(
94+
abs(row - position_row) <= 1 and abs(column - position_column) <= 1
95+
for row, column in digits_positions
96+
)

0 commit comments

Comments
 (0)