Skip to main content

wordlesolve solves Wordle!

Project description

wordlesolve

wordlesolve solves Wordle!

wordlesolve will solve almost any Wordle puzzle within six guesses. Just follow the suggestions and type in the results.

Installation

pip install wordlesolve

Usage

Solve mode

python3 -m wordlesolve

or

>>> from wordlesolve import Solver
>>> solver = Solver()
>>> solver.solve()

wordlesolve gives you up to five suggestions for each guess. Type in the guess you use and the outcome Wordle gives for each letter: 0 for grey, 1 for yellow, 2 for green.

For example if you guess RATES and get

Screenshot

enter:

Your guess:  RATES
Outcome:     02100

wordlesolve will use that information to suggest some more guesses, getting you closer to the solution each time!

Screenshot

Play mode

wordlesolve also includes a play mode - a console-based Wordle clone. Not nearly as good as the real thing but fun to practise!

python3 -m wordlesolve -p

or

>>> from wordlesolve import Solver
>>> solver = Solver()
>>> solver.play()

Screenshot

Test mode

Also included is a test mode - this was originally intended to test the algorithm during development. Test mode runs the solve algorithm against any number of solutions, either provided or randomly selected from the built-in database, and provides information on how quickly each was solved.

python3 -m wordlesolve -t -c 10 -v

or

>>> from wordlesolve import Solver
>>> solver = Solver()
>>> solver.test(count=10, verbosity=1)

Screenshot

Options

Each wordlesolve mode takes a number of options, either as command line switches or keyword arguments.

Command line Keyword Type Description Solve mode Play mode Test mode
‑‑hard hard bool Use hard mode yes yes yes
-g ‑‑guessfreq guess_freq float Minimum word frequency allowed for guesses yes yes yes
‑‑solutionfreq solution_freq float Minimum word frequency allowed for solutions no yes yes
-v ‑‑verbosity verbosity count (cl) int (kw) Verbosity level for test results no no yes
‑‑solutions solutions list[str] Solutions to test no no yes
-f ‑‑file filename str Path to a text file containing solutions to test (one word per line) no no yes

How it works

wordlesolve takes the result of each guess and builds a set of rules, for example:

Your guess:  RATES
Outcome:     02100

will generate five rules:

  • There is no R in the solution
  • There is at least one A, including one in second position
  • There is at least one T but not in third position
  • There is no E
  • There is no S

wordlesolve will then filter its database of five-letter words to keep only those that match the rules. In this case there are 113 matching words, including FAITH, FAULT, PAINT, HABIT and VAULT.

wordlesolve analyses all matching words and counts letter frequency, i.e. in how many words each letter appears once, twice, etc. So of the 113 matching words, 44 have at least one letter N, but only 2 contain the letter X. A similar analysis is run for the position of each letter, so for example 52 of the 113 words begin with the letter T, and 39 end with the letter T.

wordlesolve applies a mask to these counts, to remove any letters or positions that are already known e.g. as there is no E in the solution, all E scores will be set to zero; because we know there is an A in position 2, no score will be given for an A in position 2.

wordlesolve then returns to the full list of words and scores each word according to these frequency and position scores. If a word contains at least one letter N, it will gain 44 points; if it begins with a T it will gain 52, etc. (In hard mode only the list of matching words is analysed rather than the full word list)

These scores are added together to give each word a total, indicating how useful the word will be in confirming or eliminating the remaining matches. Based on this list, wordlesolve makes up to five suggestions for the next guess.

Word frequency

wordlesolve has a database of almost 13,000 five-letter words (the same list used in the original Wordle game). Many of these words are quite obscure and will not be known to most users. For that reason wordlesolve uses the wordfreq library to use only more frequently encountered words wherever appropriate.

wordfreq is used in 2 ways:

  • To set minimum word frequency limits for guesses or solutions via keyword arguments guess_freq / solution_freq or their command line equivalents
  • To tie-break between words with equal scores (the more frequent word will be preferred)

The wordfreq.zipf_frequency() function is used throughout - for the words in the wordlesolve database this gives a frequency of between 0.0 (very rare) and 6.4 (very common).

But why?

Wordle is fun to play - that's why it's been so successful. The idea of writing a Wordle solver was not to spoil anyone's fun, it was just an interesting challenge.

Inspired by this blog post flagged by Pycoder's Weekly I thought this would be fun to try - and it was.

Feel free to play around and let me know what you think.

Release History

  • 0.1.1
    • Fixed bug when passing a testcount number from the command line
  • 0.1.0
    • Initial release

Meta

Neil Martin – neilmartin12@me.com

Distributed under the MIT license. See LICENSE for more information.

https://github.com/neilmartin12/wordlesolve

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wordlesolve-0.1.1.tar.gz (572.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wordlesolve-0.1.1-py3-none-any.whl (55.1 kB view details)

Uploaded Python 3

File details

Details for the file wordlesolve-0.1.1.tar.gz.

File metadata

  • Download URL: wordlesolve-0.1.1.tar.gz
  • Upload date:
  • Size: 572.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for wordlesolve-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2ad505438e9b99c4b30f7372c78269f8404abb82f22253f9c9a40807bc2954a2
MD5 4a22c327049011603002297e160d01e6
BLAKE2b-256 28ca79b3818537e5f2ad90a7016231de68fa1649ffa0b2fb489ff4f61d368fae

See more details on using hashes here.

File details

Details for the file wordlesolve-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: wordlesolve-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 55.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for wordlesolve-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 836a4469e1e932ec704709a0a7da7c4ed91c453b5125daa853bd2d2eb3691683
MD5 c6400874e5c975dd9dcb6c6ef2756ead
BLAKE2b-256 e6f66c40c9ec5fd9532cf9bec6f00f516f40e26061fee2b1c74794431a000e38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page