Wordle Helper

Introduction

Wordle is a word puzzle game where players have 6 guesses to determine the correct 5-letter word. After each guess, the puzzle tells you if each letter is either:

  • Not in the word OR
  • In the word but a different location OR
  • In the word and in that location

This was recently introduced to me and the simplicity and logic of it is beautiful. The NY Times Wordle and Wordle Unlimited are my favorites.

Since programming is fun, I thought why not create a Wordle Helper to assist in guessing the word and share it with the world.

Usage

The Wordle Helper lets one enter the excluded letters and lets one enter the included letters and whether or not they’re in a specific location or not. Based on that input, it’ll tell you the remaining eligible words and suggested words to use for the next guess. Some other Wordle helpers I’ve tried don’t let one specify the same letter is not in multiple locations which eliminates the candidate words further.

Try my Wordle Helper and leave your comments below. Read on for additional info.

Technical Details

The Wordle helper is hosted on a public page on a Salesforce community in my developer edition org. When it first loads, it retrieves all the 5 letter English words that are stored in two Apex classes. Those words were parsed out from this Source Dictionary at this Github Repo. A single Lightning Web Component (LWC) does all the processing in Javascript. The component has 15,918 5-letter words. This seems to be more than the NY Times Wordle and Wordle Unlimited use.

The words were embedded in Apex classes so one wouldn’t have to parse out the words on each load. Originally, the candidate word filtering was done in Apex but it was too slow because Apex doesn’t let one easily manipulate strings like Javascript does. So, the code was migrated to the LWC.

After the first release, the Kabble English Word Frequency data set was found. That metadata was embedded in the component and the Source Dictionary cross-references its words with that to sort the suggested and candidate words from most-to-least common. Since the Wordle puzzles tend to use more common words, this increases the likelihood of getting the word correct.

Next Suggested Words Algorithm

Instead of only showing all the candidate words, I wanted to suggest words for the next guess that would allow the player to remove as many candidate words as possible. To do that, the remaining candidate words are determined. The remaining candidate words are analyzed to count how many words are used by each letter. Next, the code tries to see if the top 5 letters make any words and if so, it shows them, If the top 5 letters make no words, then the top 4 letters are used to see if they make any words and if so, show them. If not, show any words that have the top 3 letters in them. Otherwise, show nothing.

Next, sort the words from most-to-least commonly used. The Wordle puzzles tend to use more common words so it’s more likely the more common ones will help more.

Get Eligible Words Algorithm

Each time the Get Eligible Words is clicked, the code uses the 15,918 5-letter words available and

  1. Removes the words that contain any of the “Excluded Letters”, if any.
  2. Using the remaining words, filter the words to only those that match all the “Included Character Rules” such as “The letter R is not the second letter” or “The letter E is the last letter”.
  3. Sort the words from most-to-least commonly used. The Wordle puzzles tend to use more common words so it’s more likely the more common ones will help more.
  4. Show the count of the candidate words.
  5. Show the candidate words.

GitHub Repo

The code is available at my Github WordleHelper Repo.

Analysis

Using this Source Dictionary at this Github Repo, I wanted to determine how many 5 letter English words there are. Surprisingly, it’s hard to come across a complete list of all English words because different sources have different lists. Supposedly, there are 1 million English words but roughly 170,000 in common use according to here. That Source Dictionary has approximately 370,000 words so that is good enough for this fellow.

The analysis started with counting how many words there are for each given word length. This was mostly curiosity.

Word LengthCount of Words of This Length
126
2Have to Calculate correctly still
32,130
47,186
515,918
629,874
741,998
851,627
953,402
1045,872
1137,539
1229,125
1320,944
1414,149
158,846
165,182
178,846
181,471
19760
20359
21168
2274
2331
2412
258
260
273
282
292
300
311

Next, my goal was to determine a good starting word. For this, all 15,918 5-letter words had each letter checked to see how many words had that letter in them. The following table shows the most-to-least used letters and their word count. The letter A is the most used letter in 5-letter words which is surprising. I would’ve thought E or S.

The top 5 used letters, A E S O R, spell the word “arose” so that’s my starting word.

LetterWord Count
a8,392
e7,800
s6,537
o5,219
r5,143
i5,067
l4,246
t4,189
n4,043
u3,361
d2,811
c2,744
y2,521
m2,494
p2,299
h2,284
b2,089
g1,971
k1,743
f1,238
w1,171
v878
z474
j376
x361
q139
5 Letter Word Letters And Their Word Counts from Source Dictionary

After getting the 5 letter word frequency data from Kabble, it has 39,932 5 letter words so let’s see what its word count for each letter is:

LetterWord Count
a21942
e18907
o14626
i13749
s13683
r12185
n11446
l10375
t9855
c7421
d6970
m6957
u6805
h5633
g5584
p5511
b5003
k4966
y4617
f3208
v2597
w2391
z1868
j1485
x1456
q420
5 Letter Word Letters And Their Word Counts from Kabble

Tips

  • Use “Arose” as the starting word because those letters are the most used letters in the 5-letter words.
  • When using a suggested word for the next guess, choose one that you know. This seems to produce better results because the puzzles tend to use more “common” words.
  • Use words without duplicate letters to help eliminate additional letters if possible.
  • If no suggested words found, choose a word you know from the candidate words. This tends to happen when there are few remaining candidate words.

Limitations

  • The 5-word dictionary used appears to be a superset of the words used in the Wordle puzzles online so a suggested or candidate word shown may not be considered a word by the puzzle.
  • This tool doesn’t guarantee the word will be guessed right.

To Dos

  • Trim the 5-letter dictionary to only the “common” words used. One could code a little script to lookup each word at dictionary.com to see if it “exists” and exclude it if not. If one has this already, please share!
  • Get more 5-letter metadata. It would be very useful to rank the suggested and candidate words based on their “usage frequency” so that the more commonly used ones are shown first. Was able to get the list of English words and their frequency in literature from Kabble. Using that data, the suggested and candidate words are now sorted from most-to-least common.
  • Refactor the LWC Javascript code into service classes so it’s organized better.
  • Genericize the Wordle helper to assist with Wordle puzzles of any length.

This was a lot of fun to produce and hopefully it helped you out too!