Linty bits

This commit is contained in:
2023-10-20 08:22:16 -04:00
parent b672131cfc
commit accf0d0c2b
3 changed files with 16 additions and 11 deletions
+10 -9
View File
@@ -15,17 +15,18 @@ def matrix_spiral_path(matrix: list[list[int]]) -> list[tuple[int, int]]:
return snek.path
COMPASS = (
(1, 0), # east
(0, 1), # south
(-1, 0), # west
(0, -1), # north
)
class SpinSnek:
def __init__(self, board: list[list[int]], loc: tuple[int, int] = (0, 0)):
self.max_loc: tuple[int, int] = (len(board[0]) - 1, len(board) - 1)
self.spinner: itertools.cycle[tuple[int, int]] = itertools.cycle(
[
(1, 0), # east
(0, 1), # south
(-1, 0), # west
(0, -1), # north
]
)
self.spinner: itertools.cycle[tuple[int, int]] = itertools.cycle(COMPASS)
self.direction = next(self.spinner)
self.path: list[tuple[int, int]] = [loc]
self.missteps: int = 0
@@ -45,7 +46,7 @@ class SpinSnek:
or next_loc in self.path
):
self.direction = next(self.spinner)
if self.missteps > 3:
if self.missteps > len(COMPASS) - 1:
return False
self.missteps += 1