I enjoy crosswords, but sometimes I cant find (or don't even know) a valid word, to make my life easier, instead of going online or looking in a dictionary I automated the looking with Python.
In the below examples I have used a popular word puzzle app in Bulgaria that I play.
The mobile app has some random letters and the goal is to create a valid word.
Problem is often you get stuck on a word and to get a hint, you need to spend money.
You can clone this repository and run the main.py file.
First you need to be in the cloned repository and then you can run:
py main.py
Creating a virtual environment is recommended, you can create like this
py -m venv venv
- In the dropdown menu choose the desired length of the output words.
- Enter the letter sequence in the text input bar.
- Click the Generate button.
Program output | Crossword |
---|---|
The cache functionality uses a Python dictionary to cache previous queries, future quires that are stored in the dictionary are instantly returned.
This functionality validates the inputs displays the appropriate error message if any are wrong.
The file manager system manages the txt files containing all the words.
- A script called length_splitter splits the words from the base txt
file in to length specific files containing only words with equal lengths,
this limits the search only to words with the same length as the desired one.
All the separate length files are present by default.
To run the script use:py .\valid_words\lenght_splitter.py
This program uses a txt file of bulgarian words, when a query is made with a sequence of elements and a specific length, a permutation function is called and all permutations with the given length are created and stored in a list, a validate word function is called and a loop runs through the list of validated words, and checks if any of them match the permutations.
While the program uses a list of 230k+ validated Bulgarian words, some of the mobile app's words may not appear in the words list.