If you haven't been living under a rock, you probably have been playingWordle. Like a lot of people I kinda started playing it daily, and like a lot of developers I started looking for ways to algorithmically crack it. Eventually I ended up writing aWordle Solverwhich can reliably crack wordles in 4 moves or less.
I just thought I'd walk you through how I created this tool and how it works.
Finding words which match
The first thing I set out to work on was to find an algorithm which, given a word list and a guess, would filter out the words which can be possible answers to that wordle.
So I wrote this huge function to compare a guess to see if it matches:
functioncompareGuess(guess,color,answer){constmatched=[];constlen=guess.length;for(leti=0;i<len;i++){if(answer[i]===guess[i]){if(color[i]!=='g')returnfalse;matched.push(i);}else{if(color[i]==='g')returnfalse;if(color[i]==='y'){constindexes=getAllIndexes(answer,guess[i])constfiltered=indexes.filter(index=>!matched.includes(index))if(filtered.length===0)returnfalse;constfirst=filtered[0];matched.push(first);}if(color[i]==='k'/* printers */||color[i]==='b'){constallOccurances=getAllIndexes(answer,guess[i]);constfiltered=allOccurances.filter(index=>!matched.includes(index));if(filtered.length>0&&!(guess[filtered[0]]===answer[filtered[0]]))returnfalse;}}}returntrue;}
I didn't expect it to be so big!
Next I just ran it through a list of all 13 thousand allowed words on wordle and then picked out the best words.
I didn't use the smaller 2k set of possible answers because I felt that the other words could provide more information (I'm not really sure of this but¯\_(ツ)_/¯
) and also because I didn't know where to find that list 🤣
This works, but there's a problem. It gives us words in alphabetic order and sometimes you can get words likeaahed
which don't really sound like real words and which are unlikely to be the answer.
So, I applied a sorter which sorted words with higher probability first.
You can try it out yourself by cloning therepo and runningnode index.js
The future
This solver is not done yet! I've got a few more ideas to implement.
I tried making an algorithm which sorts the words which cut down our list of words the most, but it ended up crashing my computer 🤣. I will try rewriting it in a more efficient language like rust, go or c and give it a try.
Do you have any ideas on how to make this more efficient? Feel free to comment!
Top comments(2)

- Email
- LocationKannur, Kerala, India
- Joined
True, I just felt my current method would be more flexible as I add more updates!
For further actions, you may consider blocking this person and/orreporting abuse