summaryrefslogtreecommitdiffstats
path: root/aoc
diff options
context:
space:
mode:
Diffstat (limited to 'aoc')
-rw-r--r--aoc/datastructures.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/aoc/datastructures.py b/aoc/datastructures.py
index 1f141e2..9c9594a 100644
--- a/aoc/datastructures.py
+++ b/aoc/datastructures.py
@@ -30,6 +30,14 @@ class Coordinate(namedtuple("Coordinate", ["x", "y"])):
30 py, 30 py,
31 ) 31 )
32 32
33 def in_bounds(self, field: list[list]) -> bool:
34 return not (
35 self.x < 0
36 or self.y < 0
37 or self.y > len(field) - 1
38 or self.x > len(field[0]) - 1
39 )
40
33 def neighbours(self, no_diagonal: bool = False) -> Iterator["Coordinate"]: 41 def neighbours(self, no_diagonal: bool = False) -> Iterator["Coordinate"]:
34 if no_diagonal: 42 if no_diagonal:
35 yield self + Coordinate(-1, 0) 43 yield self + Coordinate(-1, 0)