Helper function to solve knight tour problem.
(
board: list[list[int]], pos: tuple[int, int], curr: int
)
| 47 | |
| 48 | |
| 49 | def open_knight_tour_helper( |
| 50 | board: list[list[int]], pos: tuple[int, int], curr: int |
| 51 | ) -> bool: |
| 52 | """ |
| 53 | Helper function to solve knight tour problem. |
| 54 | """ |
| 55 | |
| 56 | if is_complete(board): |
| 57 | return True |
| 58 | |
| 59 | for position in get_valid_pos(pos, len(board)): |
| 60 | y, x = position |
| 61 | |
| 62 | if board[y][x] == 0: |
| 63 | board[y][x] = curr + 1 |
| 64 | if open_knight_tour_helper(board, position, curr + 1): |
| 65 | return True |
| 66 | board[y][x] = 0 |
| 67 | |
| 68 | return False |
| 69 | |
| 70 | |
| 71 | def open_knight_tour(n: int) -> list[list[int]]: |
no test coverage detected