Message Boards Message Boards

A Wolfram Language facsimile of Wordle

enter image description here

The popular game Wordle can take up a lot of your time. The author designed it so that it you can only play it once a day, thus saving us from ourselves :-).

Wordle

NYTimes article on Wordle

But I couldn't resist the challenge to create a version of it in Mathematica, just for fun and because I was bored this past weekend.

See the attached notebook and enjoy. Alas, since you can run it any number of times you are only to blame for yourself it you spend too much time on it.

After executing the notebook just execute

MWordle[Deploy]

to bring up the game.

A few additional comments. The notebook MWordle.nb has the option

AutoGeneratedPackage -> Automatic

which causes it, when saved, to create an MWordle.m package file in its same directory.

The code in MWordle.nb is set up as a package with the context MWordleMwordle

If you want to set things up so that the package gets loaded and the MWordle game is automatically launched, do the following.

Create a directory MWordleGame on your disk (The name MWordleGame can actually be whatever you wish.) And in the MWordleGame directory create a new directory called MWordle. (This name must be exactly that so that the MWordleMwordle Context is property respected.) Put the MWordle.nb notebook in the MWordle dierectory, open it in Mathematica and save it so that the MWordle.m file is created in the MWordle directory. Then you can close the MWordle.nb notebook.

Now in your MWordleGame directory save a new notebook -- you can call it whatever you wish, but something like LaunchMwordle.nb is a sensible choice.

In that notebook create a button with the following command:

CellPrint[TextCell[Button["Launch MWordle",
   Monitor[
    If[! MemberQ[$Path, NotebookDirectory[]], 
     AppendTo[$Path, NotebookDirectory[]]];
    Needs["MWordle`MWordle`"]; MWordle`MWordle`MWordle[Deploy],
    Row[{ProgressIndicator[Appearance -> "Necklace", 
       ImageSize -> Small], Spacer[5], 
      Style["Launching MWordle...", 12, Blue, 
       FontFamily -> "Arial"]}]],
   Method -> "Queued"], "Text", GeneratedCell -> False, 
  CellAutoOverwrite -> False]]

You now have a button in your LaunchMwordle.nb notebook which you can use any time you want to launch MWordle without having to execute the cells in the MWordle.nb notebook.

Download the actual notebook from the link at the end of this post. The following is a version here to read.

Attachments:
POSTED BY: David Reiss
31 Replies

I used to be able to execute and play the MWordle notebook perfectly fine on 11.2, but on 13.1 I'm getting an error message when I try to evaluate the notebook. The message is:

Error: No previous context defined.

I followed the link to the error message help page, and saw something about how the function EndPackage was updated for v13. Does this mean that the MWordle.nb notebook (the one attached to David's post) is outdated for v13?

Thanks.

I just checked loading it on 13.1 (OSX) from my local notebook (which should be the same one that I uploaded to this post way back when) and it works fine. So I can't say what might be happening. I also downloaded if from this post and tested it and it worked fine as well. Perhaps something got corrupted in your download?

POSTED BY: David Reiss

Hey David,

Thanks for your quick response. I found out that I had made a foolish mistake. For some reason I was thinking that I had to execute EndPackage[] before MWordle[Deploy]. It works now. As a side note, the game is a great and clever adaption of the real thing! Thanks for taking the time to post it. :-)

Eleazar, Great! I am glad you figured it out. Enjoy! It was a fun exercise to make it, and it amused my daughter ;-) Best, David

POSTED BY: David Reiss

Another interesting Wordle implementation in Mathematica:

n-Wordle

It's a world of Wordles!

POSTED BY: David Reiss

And for something elseā€¦

Worldle, not Wordle

POSTED BY: David Reiss

I wrote a small blog post on this which you can read here:

Wordle the Wolfram Way

POSTED BY: David Reiss

It seems that Wordle was just sold to the New York Times:

New York Times press release

POSTED BY: David Reiss

An interesting statistics that just went viral on Reddit:

enter image description here

POSTED BY: Vitaliy Kaurov

Using this, someone should really train an agent to play Wordle at a high level.

POSTED BY: Peter Barendse

Sure (though I prefer to keep a sense of mystery each time I do the real Wordle). Arnoud has written an blog post with some additional analysis using the ResourceFunction that contains the actual Wordle words that he scraped. Here is the link to that (posted with his permission):

Tips and Tricks for Solving Wordle Efficiently

The takeaway is, of course, that you can easily analyze strategies with the Wolfram Language and, of course, have fun doing it!

POSTED BY: David Reiss

It seems that both things are true?

In[]:= Complement[wordleWords, my5LetterWords][[-10 ;;]]

Out[]= {"zulus", "zupan", "zupas", "zuppa", "zurfs", "zuzim", \
"zygal", "zygon", "zymes", "zymic"}

And, for example, "zygal" is a word):

zygal definition on Dictionary.com

"Having a shape like a yoke or like the letter H"

When it comes to "zulus", for example,

In[]:= DictionaryWordQ["Zulu"]

Out[]= True

It seems that the plural is not in the way that I retrieved the 5 letter words and that I'd need to be more careful in making sure that the various plurals are in my list (and making sure that I take care of capitalization as I do it):

In[]:= Pluralize["Zulu"]

Out[]= "Zulus"

So, I am the student that this exercise is intended for!

POSTED BY: David Reiss

Fair enough... thanks!

POSTED BY: Arnoud Buzing

I updated the code to catch plurals like "Zulus". I still find that the WordList "KnownWords" dictionary does not contain, for example, some words that are conjugations of verbs. Perhaps I am not quite understanding what the restrictions on WordList["KnownWords"] is.

In[]:= MemberQ[WordList["KnownWords"], "ate"]
Out[]= False

In[]:= MemberQ[WordList["KnownWords"], "walked"]    
Out[]= False

And I find this strange when, for example,

In[]:= WordData["ate", "PartsOfSpeech"]    
Out[]= {"Verb"}

And

In[]:= DictionaryWordQ["ate"]    
Out[]= True

BTW, I came across this issue when I was checking today's (1/30) online word for Wordle (slight spoiler in that).

POSTED BY: David Reiss

I found Wordle's word list online and put it in a ResourceObject:

ResourceData[
 ResourceObject[
  CloudObject[
   "https://www.wolframcloud.com/obj/arnoudb/DeployedResources/Data/Wordle-Word-List"]]]

More information here:

https://www.wolframcloud.com/obj/arnoudb/DeployedResources/Data/Wordle-Word-List

POSTED BY: Arnoud Buzing

Thanks Arnoud!

POSTED BY: David Reiss

So this raises an interesting question about the words contained in Mathematica's WordList.

Here are the 5 letter words that I have used from WordList["KnownWords", IncludeInflections -> True]:

my5LetterWords =
  Module[{words},
    words = 
    Select[WordList["KnownWords", IncludeInflections -> True], 
     StringLength[#] === 5 &];
   words = Select[words, StringMatchQ[#, LetterCharacter .. ] &];
   Union[words]
   ];

And here are the words that Arnoud put in the ResourceObject:

wordleWords = 
  ResourceData[
   ResourceObject[
    CloudObject[
     "https://www.wolframcloud.com/obj/arnoudb/DeployedResources/Data/\
Wordle-Word-List"]]];

There are quite a few more in wordleWords than in my5LetterWords:

In[]:= Length /@ {my5LetterWords, wordleWords}

Out[]= {7766, 12972}

Here are how many more are in the wordle words:

In[]:= Length[Complement[wordleWords, my5LetterWords]]

Out[]= 6854

And there are some missing in the other direction:

In[]:= Length[Complement[my5LetterWords, wordleWords]]

Out[]= 1648

So, exercise for the interested student: what is going on here, and is Mathematica's dictionary a bit too sparse?

POSTED BY: David Reiss

There's nothing wrong with the WL dictionaries, the Wordle word list seems to include a lot of "non-words". Not sure why, but the Wordle game does accept those "non-words" on that list (I checked a few).

I've added a few more "solving tricks" here: https://arnoudbuzing.medium.com/tips-and-tricks-for-solving-wordle-efficiently-28ab67a52dbf

POSTED BY: Arnoud Buzing

It's amazing how many words I don't know. I think some human it picking the secret words, though. Given the list of them so far, it seems to be a different dictionary than the accepted words (maybe the average of their use-frequency is statistically higher than that of other dictionaries?)

POSTED BY: Peter Barendse

Congratulations! Your post was highlighted on the Wolfram's official social media channels. Thank you for your contribution. We are looking forward to your future posts.

POSTED BY: Moderation Team

There is a lot of chatter on the internet about this question (as we would expect!). Just Google "best words for Wordle" and feast your eyes. Though I prefer to leave an air of mystery to my use of the game, I can't help but take a crack at this over my morning coffee. Here's one approach:

POSTED BY: David Reiss

Nice! It's great to see how compact this is!

POSTED BY: Danny Finn

I was thinking it would be good to compute what the best starting word would be for wordle based on WordData, letter frequencies and letter position frequencies. The final word has to be a real 5-letter word as a constraint. So far I haven't tried out any analysis though. Usually I use AUDIO or TEARS although it would be nice to have a top ten best words to pick from.

POSTED BY: Danny Finn

I think about characters rather than words, since I am looking for the most used characters

So for example if I am looking for 4-letters word, I use NEAT or something similar, but your logic is interesting and I want to try coding it.

POSTED BY: Ahmed Elbanna

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: Moderation Team
Posted 2 years ago

Wordle post on MSE.

POSTED BY: Rohit Namjoshi

Thanks! I put a link to this post as a reply on that stackexchange post. Update: I did not see that you had added a link to here as a comment, but I will leave mine up as well and let the moderators choose whether to delete it. Thanks again!

POSTED BY: David Reiss

Hi David,

thanks for sharing this interesting code!

It is fun to note that [...] the web version of Wordle it is about 2000 lines of code. The facsimile in Mathematica [...] is a bit more than 350 lines of code.

Exactly - the Mathematica version of code appears virtually always to be shortest. This can also be seen in an impressive way at rosettacode.org, where an incredible lot of programming languages are compared.

POSTED BY: Henrik Schachner

Thanks! It was fun to create on a slow Sunday evening.

POSTED BY: David Reiss

It is fun to note that, if you look at the javascript code for the web version of Wordle it is about 2000 lines of code. The facsimile in Mathematica (which admittedly does not have quite the same functionality as the original) is a bit more than 350 lines of code.

POSTED BY: David Reiss

For those who want to cheat, I have added a cheating button that gives you the answer if you have enabled it with the checkbox next to it. But, don't cheat! ;-)

  • I have updated the notebook and changed the name of the application from Wordle to MWordle. And I have added some usage messages to the functions and parameter in the notebook. Also I have added one more row to the set of possible guesses that you can make so it has the same array size as in the original web version of the game.

  • Added a small update with a menu to let the user choose the part of speech to use in the puzzle: all words, nouns, verbs, or adjectives.

  • I added a but more to my original post with instructions on how to set things up so that you can launch the MWordle game from a custom notebook via a simple button.

  • I have updated the MWordle.nb notebook attached to this post with some additional commentary within it. The full notebook is also posted inline in the top level post. However, download the attached notebook to play with the code directly.

  • I updated the main post with a screenshot of the game. Enjoy!

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract