We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d73a036 commit 0dd2b8dCopy full SHA for 0dd2b8d
backtracking/word_search_path.py
@@ -60,6 +60,21 @@ def get_word_path(
60
) -> list[tuple[int, int]] | None:
61
"""
62
Return the coordinate path if it's possible to find the word in the grid.
63
+
64
+ >>> board = [["C", "A", "T"], ["X", "Y", "S"], ["A", "B", "C"]]
65
+ >>> # 1. Find "CATS" starting at (0,0). Initial key is 0.
66
+ >>> get_word_path(board, "CATS", 0, 0, 0, {0}, [])
67
+ [(0, 0), (0, 1), (0, 2), (1, 2)]
68
69
+ >>> # 2. Find "BC" starting at (2,1).
70
+ >>> # Key for (2,1) in 3x3 is: (3 * 3 * 2) + 1 = 19
71
+ >>> get_word_path(board, "BC", 2, 1, 0, {19}, [])
72
+ [(2, 1), (2, 2)]
73
74
+ >>> # 3. Partial search: current_path already has (0,0), looking for "ATS" starting at (0,1)
75
+ >>> # Key for (0,1) is 1. Visited includes the 'C' at key 0.
76
+ >>> get_word_path(board, "ATS", 0, 1, 0, {0, 1}, [(0, 0)])
77
78
79
80
if board[row][column] != word[word_index]:
0 commit comments