diff options
| author | 2025-12-04 17:06:44 +0100 | |
|---|---|---|
| committer | 2025-12-04 17:06:44 +0100 | |
| commit | c641dda28310318af8bd0fa6f72a5e1dbc723dac (patch) | |
| tree | 670c9445812ac70e01a3d5edd4ca69c582529515 /aoc | |
| parent | 89929901e88749c8428afd0cf5684caa49a246b7 (diff) | |
| download | 2025-main.tar.gz 2025-main.tar.bz2 2025-main.zip | |
Added day4main
Diffstat (limited to 'aoc')
| -rw-r--r-- | aoc/datastructures.py | 8 |
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) |
