This is a JavaScript port of HackerPoet (aka CodeParade)'s WordSquares, with more features and a command line interface.
A simple JavaScript solver for dense word grids.
See CodeParade's YouTube video for the best explanation on WordSquares.
To use this solver, you'll first need a list of valid words and a word frequency list. If you'd like to use the same files as shown in CodeParade's video, follow these links:
- Dictionary file: Scrabble Words List
- Frequencies file: NGram Viewer Frequencies
Run the solver by using npx wordsquares <path_to_your_dictionary_file> <path_to_your_frequencies_file>.
By default, the width and height are 5. You can change this by specifying the dimensions at the end like <width>x<height>. For example, 4x6 would set the width to 4 and height to 6.
By default, each word must be within the top 20,000th words. You can change this with the -f or --frequency flag.
To change the width/height minimum frequency individually, use --fw for width or --fh for height.
If you need each result to include certain word(s), use the -i or --includes flag. Note that every result will be checked to see if it includes ALL words you specify.
You can specify these words either in the argument directly as a string, or supply a path to a file to read the words from. Separate each word with a comma or newline. You can also use asterisks (*) or spaces as wildcard characters.
If you want to exclude certain word(s), use the -x or --excludes flag. You can then specify these words either in the argument directly as a string, or supply a path to a file to read the words from. Separate each word with a comma or newline. You can also use asterisks (*) or spaces as wildcard characters.
You can specify a template that each result must follow using the -t or --template flag. You can specify this template either in the argument directly as a string, or supply a path to a file to read the template from. Separate each row with a comma or newline. Use asterisks (*) or spaces as wildcard characters. The template must be the same dimensions as the results you're generating.
You can limit the number of results by using the -m or --max-results flag.
You can output all results to a text file instead of the console with the -o or --output.
Use the -u or --unique flag to only show WordSquares that have all unique words. This is applicable only to square grids.
Use the -d or --diagonals flag to also check if the diagonals are valid words.
npx wordsquares scrabble_words.txt ngram_freq_dict.csv 4x4
npx wordsquares scrabble_words.txt ngram_freq_dict.csv -f 10000
npx wordsquares scrabble_words.txt ngram_freq_dict.csv -t "*****,*****,ROOTS,*****,*****"
This template would look like:
*****
*****
ROOTS
*****
*****
A possible solution to this template is:
SWAMP
THREE
ROOTS
ASSET
PEERS