Skip to content

Instantly share code, notes, and snippets.

@jsundram
Last active November 4, 2022 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsundram/3abc6a3b931d9edb7057b95d56641b14 to your computer and use it in GitHub Desktop.
Save jsundram/3abc6a3b931d9edb7057b95d56641b14 to your computer and use it in GitHub Desktop.
Solving the Spelling Bee (https://www.nytimes.com/puzzles/spelling-bee) with a one-liner in Bash
#!/usr/bin/env bash
# Solve the Spelling Bee (https://www.nytimes.com/puzzles/spelling-bee)
# Usage `./bee.sh ulroapn | more` where the first letter is the one in the middle
# Output: a list of valid dictionary words that contain the first letter and
# no letters that aren't on the list provided.
# Unfortunately the MacOS dictionary has words that aren't in the custom
# Spelling Bee dictionary, so you may find words listed that aren't accepted
# by the spelling bee app.
letters=$1
center=${letters:0:1} # Assumes first letter is the middle one
# This used to be a one-liner but I decided to make it more readable.
egrep -w "^[$letters]+" /usr/share/dict/words | grep $center | # Get all the words that match
awk -v number= '{ if (length > 3) print length, $0 }' | # Prefix them with their length if they are longer than 3 letters
sort -rn | # Sort numerically in reverse (longest first)
cut -d" " -f2- # Remove the length prefix.
@jsundram
Copy link
Author

jsundram commented Nov 4, 2022

Alternatively, just do window.gameData.today.answers in the javascript console. Or, to have it sorted nicely:

window.gameData.today.answers.sort( (a, b) => a.length > b.length ? 1 : a.length < b.length ? -1 : (a > b ? 1 : a < b ? -1 : 0))

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