A Wolfram Language facsimile of Wordle

Wordle.gif

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.

MWordle.nb (114 KB)

25 Likes

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! :wink:

  • 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!

2 Likes

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.

3 Likes

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.

3 Likes

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

Wordle post on MSE.

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!

news-congrads-kkluyshnik-02-04-19.jpg – you have earned Featured Contributor Badge 2015-11-02_10-07-11.png
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!

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.

3 Likes

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.

3 Likes

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:

3 Likes

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.

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

1 Like

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

4 Likes

Thanks Arnoud!

1 Like

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?

2 Likes

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

1 Like

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!

1 Like

Fair enough… thanks!

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

1 Like