create word search path retrieval with comprehensive doctests#14504
create word search path retrieval with comprehensive doctests#14504maknelso wants to merge 6 commits intoTheAlgorithms:masterfrom
Conversation
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| return len_board * len_board_column * row + column | ||
|
|
||
|
|
||
| def get_word_path( |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file backtracking/word_search_path.py, please provide doctest for the function get_word_path
There was a problem hiding this comment.
added doctests for get_word_path():
"""
Return the coordinate path if it's possible to find the word in the grid.
>>> board = [["C", "A", "T"], ["X", "Y", "S"], ["A", "B", "C"]]
>>> # 1. Find "CATS" starting at (0,0). Initial key is 0.
>>> get_word_path(board, "CATS", 0, 0, 0, {0}, [])
[(0, 0), (0, 1), (0, 2), (1, 2)]
>>> # 2. Find "BC" starting at (2,1).
>>> # Key for (2,1) in 3x3 is: (3 * 3 * 2) + 1 = 19
>>> get_word_path(board, "BC", 2, 1, 0, {19}, [])
[(2, 1), (2, 2)]
>>> # 3. Partial search: current_path already has (0,0), looking for "ATS" starting at (0,1)
>>> # Key for (0,1) is 1. Visited includes the 'C' at key 0.
>>> get_word_path(board, "ATS", 0, 1, 0, {0, 1}, [(0, 0)])
[(0, 0), (0, 1), (0, 2), (1, 2)]
>>> # 4. Failure case: First letter doesn't match current cell
>>> get_word_path(board, "DOG", 0, 0, 0, {0}, []) is None
True
"""
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| return len_board * len_board_column * row + column | ||
|
|
||
|
|
||
| def get_word_path( |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file backtracking/word_search_path.py, please provide doctest for the function get_word_path
There was a problem hiding this comment.
added doctests for get_word_path():
"""
Return the coordinate path if it's possible to find the word in the grid.
>>> board = [["C", "A", "T"], ["X", "Y", "S"], ["A", "B", "C"]]
>>> # 1. Find "CATS" starting at (0,0). Initial key is 0.
>>> get_word_path(board, "CATS", 0, 0, 0, {0}, [])
[(0, 0), (0, 1), (0, 2), (1, 2)]
>>> # 2. Find "BC" starting at (2,1).
>>> # Key for (2,1) in 3x3 is: (3 * 3 * 2) + 1 = 19
>>> get_word_path(board, "BC", 2, 1, 0, {19}, [])
[(2, 1), (2, 2)]
>>> # 3. Partial search: current_path already has (0,0), looking for "ATS" starting at (0,1)
>>> # Key for (0,1) is 1. Visited includes the 'C' at key 0.
>>> get_word_path(board, "ATS", 0, 1, 0, {0, 1}, [(0, 0)])
[(0, 0), (0, 1), (0, 2), (1, 2)]
>>> # 4. Failure case: First letter doesn't match current cell
>>> get_word_path(board, "DOG", 0, 0, 0, {0}, []) is None
True
"""
a96685a to
d73a036
Compare
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| return len_board * len_board_column * row + column | ||
|
|
||
|
|
||
| def get_word_path( |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file backtracking/word_search_path.py, please provide doctest for the function get_word_path
There was a problem hiding this comment.
added doctests for get_word_path():
"""
Return the coordinate path if it's possible to find the word in the grid.
>>> board = [["C", "A", "T"], ["X", "Y", "S"], ["A", "B", "C"]]
>>> # 1. Find "CATS" starting at (0,0). Initial key is 0.
>>> get_word_path(board, "CATS", 0, 0, 0, {0}, [])
[(0, 0), (0, 1), (0, 2), (1, 2)]
>>> # 2. Find "BC" starting at (2,1).
>>> # Key for (2,1) in 3x3 is: (3 * 3 * 2) + 1 = 19
>>> get_word_path(board, "BC", 2, 1, 0, {19}, [])
[(2, 1), (2, 2)]
>>> # 3. Partial search: current_path already has (0,0), looking for "ATS" starting at (0,1)
>>> # Key for (0,1) is 1. Visited includes the 'C' at key 0.
>>> get_word_path(board, "ATS", 0, 1, 0, {0, 1}, [(0, 0)])
[(0, 0), (0, 1), (0, 2), (1, 2)]
>>> # 4. Failure case: First letter doesn't match current cell
>>> get_word_path(board, "DOG", 0, 0, 0, {0}, []) is None
True
"""
66760e3 to
0ac14b2
Compare
Describe your change:
I added a backtracking word search function that returns the path of the coordinates of each character or None if word cannot be found.
Checklist: