Linty bits
This commit is contained in:
parent
b672131cfc
commit
accf0d0c2b
@ -61,7 +61,7 @@ dependencies = [
|
|||||||
"ruff>=0.0.243",
|
"ruff>=0.0.243",
|
||||||
]
|
]
|
||||||
[tool.hatch.envs.lint.scripts]
|
[tool.hatch.envs.lint.scripts]
|
||||||
typing = "mypy --install-types --non-interactive {args:src/leetcode tests}"
|
typing = "mypy --install-types --non-interactive {args:.}"
|
||||||
style = [
|
style = [
|
||||||
"ruff {args:.}",
|
"ruff {args:.}",
|
||||||
"black --check --diff {args:.}",
|
"black --check --diff {args:.}",
|
||||||
@ -120,6 +120,10 @@ ignore = [
|
|||||||
"S105", "S106", "S107",
|
"S105", "S106", "S107",
|
||||||
# Ignore complexity
|
# Ignore complexity
|
||||||
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
|
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
|
||||||
|
# Allow print func
|
||||||
|
"T201",
|
||||||
|
# Allow assert statements
|
||||||
|
"S101",
|
||||||
]
|
]
|
||||||
unfixable = [
|
unfixable = [
|
||||||
# Don't touch unused imports
|
# Don't touch unused imports
|
||||||
|
@ -15,17 +15,18 @@ def matrix_spiral_path(matrix: list[list[int]]) -> list[tuple[int, int]]:
|
|||||||
return snek.path
|
return snek.path
|
||||||
|
|
||||||
|
|
||||||
|
COMPASS = (
|
||||||
|
(1, 0), # east
|
||||||
|
(0, 1), # south
|
||||||
|
(-1, 0), # west
|
||||||
|
(0, -1), # north
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SpinSnek:
|
class SpinSnek:
|
||||||
def __init__(self, board: list[list[int]], loc: tuple[int, int] = (0, 0)):
|
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.max_loc: tuple[int, int] = (len(board[0]) - 1, len(board) - 1)
|
||||||
self.spinner: itertools.cycle[tuple[int, int]] = itertools.cycle(
|
self.spinner: itertools.cycle[tuple[int, int]] = itertools.cycle(COMPASS)
|
||||||
[
|
|
||||||
(1, 0), # east
|
|
||||||
(0, 1), # south
|
|
||||||
(-1, 0), # west
|
|
||||||
(0, -1), # north
|
|
||||||
]
|
|
||||||
)
|
|
||||||
self.direction = next(self.spinner)
|
self.direction = next(self.spinner)
|
||||||
self.path: list[tuple[int, int]] = [loc]
|
self.path: list[tuple[int, int]] = [loc]
|
||||||
self.missteps: int = 0
|
self.missteps: int = 0
|
||||||
@ -45,7 +46,7 @@ class SpinSnek:
|
|||||||
or next_loc in self.path
|
or next_loc in self.path
|
||||||
):
|
):
|
||||||
self.direction = next(self.spinner)
|
self.direction = next(self.spinner)
|
||||||
if self.missteps > 3:
|
if self.missteps > len(COMPASS) - 1:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.missteps += 1
|
self.missteps += 1
|
||||||
|
@ -30,7 +30,7 @@ import spiral_matrix
|
|||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9],
|
[1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9],
|
[1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||||
],
|
],
|
||||||
[]
|
[] # noqa
|
||||||
+ [1, 2, 3, 4, 5, 6, 7, 8, 9] # right
|
+ [1, 2, 3, 4, 5, 6, 7, 8, 9] # right
|
||||||
+ [9, 9, 9] # down
|
+ [9, 9, 9] # down
|
||||||
+ [9, 8, 7, 6, 5, 4, 3, 2, 1] # left
|
+ [9, 8, 7, 6, 5, 4, 3, 2, 1] # left
|
||||||
|
Loading…
Reference in New Issue
Block a user