From c641dda28310318af8bd0fa6f72a5e1dbc723dac Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 4 Dec 2025 17:06:44 +0100 Subject: Added day4 --- aoc/datastructures.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'aoc') 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"])): py, ) + def in_bounds(self, field: list[list]) -> bool: + return not ( + self.x < 0 + or self.y < 0 + or self.y > len(field) - 1 + or self.x > len(field[0]) - 1 + ) + def neighbours(self, no_diagonal: bool = False) -> Iterator["Coordinate"]: if no_diagonal: yield self + Coordinate(-1, 0) -- cgit v1.2.3