Skip to content

Instantly share code, notes, and snippets.

@zemanlx
Created January 23, 2022 09:44
Show Gist options
  • Save zemanlx/741ec01203744ca5ee52d3c8b883f8af to your computer and use it in GitHub Desktop.
Save zemanlx/741ec01203744ca5ee52d3c8b883f8af to your computer and use it in GitHub Desktop.
Solving Wordle with Bash and friends: The best starting word
#!/bin/bash
# Test letter frequency counting.
echo "abbey" | grep -o . | sort | uniq -c | sort -nr
# Letter frequency of all five-letter words.
grep -o . wordle.dictionary | sort | uniq -c | sort -nr
# Find word that contains letters from "searo".
grep s wordle.dictionary | grep e | grep a | grep r | grep o
# Filter out all words that contain any letter of "arose" word.
grep -P '[^arose]{5}' wordle.dictionary | wc -l
# Build dictionaries with 4 and 3 letters.
grep -P "^[a-z]{4}$" /usr/share/dict/american-english \
> 4.dictionary
grep -P "^[a-z]{3}$" /usr/share/dict/american-english \
> 3.dictionary
# Create dictionary of four-letter words with -s suffix
# that are also in Wordle dictionary.
while read -r line; do grep "${line}s" wordle.dictionary; done \
< 4.dictionary > 4s.dictionary
# Create dictionary of three-letter words with -es suffix
# that are also in Wordle dictionary.
while read -r line; do grep "${line}es" wordle.dictionary; done \
< 3.dictionary > 3es.dictionary
# Create dictionary of three-letter words with -ies suffix
# created from words ending with 'y' that are also
# in Wordle dictionary.
while read -r line; do grep "${line/y/ies}" wordle.dictionary; done \
<<< $(grep -P 'y$' 3.dictionary) > 3ies.dictionary
# Create dictionary of four-letter words with -d suffix
# that are also in Wordle dictionary.
while read -r line; do grep "${line}d" wordle.dictionary; done \
< 4.dictionary > 4d.dictionary
# Create dictionary of three-letter words with -ed suffix
# that are also in Wordle dictionary.
while read -r line; do grep "${line}ed" wordle.dictionary; done \
< 3.dictionary > 3ed.dictionary
# Create dictionary of three-letter words with -ied suffix
# created from words ending with 'y' that are also
# in Wordle dictionary.
while read -r line; do grep "${line/y/ied}" wordle.dictionary; done \
<<< $(grep -P 'y$' 3.dictionary) > 3ied.dictionary
# Create complete dictionary of all imposters words by joining
# our partial dictionaries, sorting them and finaly picking unique
# ones for the final dictionary.
cat 3es.dictionary 3ies.dictionary 3ed.dictionary 3ied.dictionary \
4s.dictionary 4d.dictionary \
| sort | uniq > imposters.dictionary
# Filter out words from 4s.dictionary from Wordle dictionary
# and create wordle_opinionated.dictonary.
comm -23 wordle.dictionary imposters.dictionary \
> wordle_opinionated.dictionary
# Count words of opinionated dictionary.
wc -l wordle_opinionated.dictionary
# Letter frequency of all five-letter words without imposters.
grep -o . wordle_opinionated.dictionary | sort | uniq -c | sort -nr
@zemanlx
Copy link
Author

zemanlx commented Jan 25, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment