-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create word search algorithm #8906
Create word search algorithm #8906
Conversation
@tianyizheng02 Pinging for review |
# Board matrix holding each letter | ||
self.board: list[list[str | None]] = [[None] * width for _ in range(height)] | ||
|
||
def insert_north(self, word: str, rows: list[int], cols: list[int]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd help to have the block comment explain what rows
and cols
are for
shuffle(cols) | ||
|
||
# Insert the word via the direction | ||
choice(directions)(word, rows, cols) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it possible for the insert_...
functions to fail to insert a word? Can we ensure that the word will actually be inserted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct, the function will fail if there is not enough space on the board to insert the word. I will refactor the logic of the insertions to return whether or not the insertion was successful or not, and then raise and error if the insertion was unsuccessful
character = letter | ||
# Empty char, so add a fake char | ||
elif add_fake_chars: | ||
character = chr(randint(97, 122)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have input words restricted to just lowercase English letters? If you're just padding out the word search with random English lowercase letters and the user chooses words that use other characters (uppercase English letters, etc) then the inserted words would stand out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can limit to only lowercase english letters 👍
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
@CaedenPH pre-commit and build are failing due to incorrect function names, please fix:
|
* feat(other): Create word_search algorithm * updating DIRECTORY.md * doc(word_search): Link to wikipedia article * Apply suggestions from code review Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com> * Update word_search.py --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
Describe your change:
Create a word search algorithm
Checklist: