day23 better way to check moveable elves
This commit is contained in:
parent
840e7abc4d
commit
867a476c44
2 changed files with 97 additions and 75 deletions
|
|
@ -76,6 +76,16 @@ class Position:
|
|||
yield self.left()
|
||||
yield self.down()
|
||||
|
||||
def all_neighbors(self) -> Iterator[Position]:
|
||||
yield Position(self.x + 1, self.y)
|
||||
yield Position(self.x + 1, self.y - 1)
|
||||
yield Position(self.x, self.y - 1)
|
||||
yield Position(self.x - 1, self.y - 1)
|
||||
yield Position(self.x - 1, self.y)
|
||||
yield Position(self.x - 1, self.y + 1)
|
||||
yield Position(self.x, self.y + 1)
|
||||
yield Position(self.x + 1, self.y + 1)
|
||||
|
||||
def is_within(self, top_left: Position, bottom_right: Position) -> bool:
|
||||
"""
|
||||
Checks if this point is within the rectangle spanned by the given positions.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue