January 16 2022

Description

Following the trend, my parents started playing the Wordle game. If you're not familiar, it's like the Mastermind board game but with words: there's a secret word you have to guess in at most 6 attempts. The letter is colored green if it's in the right position, yellow if it's in the word but not in the right position, and black if it isn't in the word. However, the guess must be a valid word, thus can't be some jibber jabber such as "jbkazs".

Instead of attempting to beat my dad's glorious 3 attempt guess, and instead of studying for my midterm, I spent the weekend implementing a Wordle Bot while learning about Python's webscraping capabilities with Selenium.

In hindsight, this probably wasn't the most efficient strategy... My midterm still went pretty well though! :)

For the full project, here is a link to the GitHub Repo.

First Guess

First, we need to filter the UK english dictionary to obtain a list of 5 letter words. To find a good first guess, we can refer to letter frequencies in that list. We find the word which contains the 5 most frequent letters to be: arose. Here is a short Jupyter Notebook yielding exactly this result:

Results

With the Selenium webdriver tools, the program opens up the browser right in front of you and interacts with the website. Here is what a full run looks like:

Splendid! Notice the recovery when the generated guess is "lloyd", which isn't in Wordle's word list. ;)

But my dad did it in 3 guesses... Since the program works by randomly choosing words in the list given the constraints, let's see how it performs if we run it again.

Impressive! Ah-ha! In your face dad! :)

An interesting nuance in this run is the constraint set by the guess "photo". It contains the letter 'o' twice, but once in green and once in black. It's important to treat this case in order to prevent the program from filtering out the answer from the list of words.

We see the program works well even without arose as our first guess:

Different days with different words: