Skip to content
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

Merged
merged 6 commits into from
Sep 30, 2023

Conversation

CaedenPH
Copy link
Contributor

Describe your change:

Create a word search algorithm

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@CaedenPH
Copy link
Contributor Author

@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:
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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))
Copy link
Contributor

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.

Copy link
Contributor Author

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>
@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Sep 5, 2023
@tianyizheng02
Copy link
Contributor

@CaedenPH pre-commit and build are failing due to incorrect function names, please fix:

other/word_search.py:329: error: "WordSearch" has no attribute "insert_north_east"; maybe "insert_northeast", "insert_northwest", or "insert_southeast"?  [attr-defined]
other/word_search.py:331: error: "WordSearch" has no attribute "insert_south_east"; maybe "insert_southeast", "insert_southwest", or "insert_northeast"?  [attr-defined]
other/word_search.py:333: error: "WordSearch" has no attribute "insert_south_west"; maybe "insert_southwest", "insert_southeast", or "insert_northwest"?  [attr-defined]

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Sep 30, 2023
@tianyizheng02 tianyizheng02 merged commit dec9643 into TheAlgorithms:master Sep 30, 2023
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Sep 30, 2023
sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
* 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>
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants