Skip to content

Instantly share code, notes, and snippets.

@drbr
Last active November 27, 2023 05:48
Show Gist options
  • Save drbr/014d4ecc455e5a4bb9caf8b7bf7e1970 to your computer and use it in GitHub Desktop.
Save drbr/014d4ecc455e5a4bb9caf8b7bf7e1970 to your computer and use it in GitHub Desktop.
Simple shell script to help solve Wordle. It will tell tell you what the answer could be based on the yellow/green/black squares you have discovered so far.
#!/bin/zsh
# Get all the 5 letter words. This only needs to be generated once,
# so do it outside the script and leave the file on disk.
# grep '^.....$' /usr/share/dict/words > 5LetterWords.txt
# All the known green letters as a regex, e.g. `greens 'AB.C.'`
greens() {
grep -i $1
}
# Yellow letter in the 1st position
y1() {
grep -i $1 |
grep -i -v $1'....'
}
# Yellow letter in the 2nd position
y2() {
grep -i $1 |
grep -i -v '.'$1'...'
}
# Yellow letter in the 3rd position
y3() {
grep -i $1 |
grep -i -v '..'$1'..'
}
# Yellow letter in the 4th position
y4() {
grep -i $1 |
grep -i -v '...'$1'.'
}
# Yellow letter in the 5th position
y5() {
grep -i $1 |
grep -i -v '....'$1
}
# Black letter (position doesn't matter)
b() {
grep -v -i $1
}
result=$(
cat 5LetterWords.txt |
# Enter all the known info and pipe it all together
greens 'S...E' |
y1 l | y3 o |
b f | b r | b i | b t |
sort -u)
echo $result | less
wordCount=$(echo $result | wc -l)
echo $wordCount words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment