Node Boggle Solver
Using JavaScript to generate a Boggle board and then find every English word in that board. All the words are stored in a trie for efficiency. Use as a command line tool or a NodeJS module.
npm install solve-boggle
Boggle solver module
You can supply the letters to the board in the constructor.
const Boggle = ; let boggle = 'adofhptogijrstjg'; // letters for 4x4 board from left-to-right then top-to-bottemboggle;
The board can theoretically be any NxN size. This is efficient enough to handle 200x200 boards in less than a second. They can be generated randomly from the boggle dice if N is between 4 and 6 inclusive.
const Boggle = ; let boggle1 = 'CLEINRTSHBNFAOUIEERGTPUNE'; // 5x5 boardlet boggle2 = 'sdjgneraghpareugnaeporigrpeouganerkgjarpehgaeraetusnviehtvndjfgd'; // 8x8 board let boggle3 = 6; // roll the dice for a 6x6 boardlet boggle4 = 5;let boggle5 = ; // defaults to 4
Check for individual words in the board.
let boggle = 'eorgvregearjkgoe';boggle;boggle;
Boggle solver CLI
The argument to the command is the same as the argument you would be giving to the Boggle constructor function.
node_modules/.bin/solve-boggle erogijeratierstp
┌───┬───┬───┬───┐
│ E │ R │ O │ G │
├───┼───┼───┼───┤
│ I │ J │ E │ R │
├───┼───┼───┼───┤
│ A │ T │ I │ E │
├───┼───┼───┼───┤
│ R │ S │ T │ P │
└───┴───┴───┴───┘
103 words
AIR, ATE, ART, ERE, EGO, ERG, ETA, GET, GEE, IRE, ITS, JAR, JOG, JET, ORE, PER, PIS, PIT, PEE, PET, PIE, RAT, REP, RIP, ROE, SIP, SIR, SIT, SAT, TEE, TAR, TIP, TIE, TIT, ARTS, ERGO, GRIP, GRIT, GORE, GETS, JEEP, JEER, JETS, JARS, OGRE, PETS, PIER, PITS, PITA, PEER, RATE, RATS, RIPE, RITE, REIS, SATE, STIR, SIRE, STAR, SITE, STEP, TITS, TSAR, TARS, TIRO, TIRE, TIER, ASTER, ASTIR, EERIE, EGRET, GRIST, GRITS, GREET, GRIPE, ROGER, STEER, SITAR, STAIR, STEEP, TASTE, ATTIRE, ARTIER, ARTIST, EGRETS, GREETS, GORIER, PETITE, RASTER, REGRET, RETIRE, SATIRE, SITTER, STEREO, TASTER, ARTSIER, ARTISTE, PETTIER, REGRETS, RATTIER, TASTIER, GRITTIER, JITTERIER
Instead, you can install globally...
npm install -g solve-boggle
and invoke the command like this.
solve-boggle erogijeratierstp
Documentation
Boggle
Class representing a Boggle board.
Kind: global class
- Boggle
- new Boggle([boardParam])
- instance
- inner
- ~solveCallback :
function
- ~containsCallback :
function
- ~solveCallback :
new Boggle([boardParam])
Create an NxN board.
Param | Type | Default | Description |
---|---|---|---|
[boardParam] | string | number |
4 |
Either a string with the board's letters (left-to-right top-to-bottom), or a size N. |
boggle.print()
Format the board as a string and write to stdout.
Kind: instance method of Boggle
boggle.toString()
Convert the board to a string.
Kind: instance method of Boggle
boggle.solve(done)
Finds all English words in the board.
Kind: instance method of Boggle
Param | Type | Description |
---|---|---|
done | solveCallback |
Callback to run when done solving. |
boggle.contains(target, done)
Finds one English word in the board.
Kind: instance method of Boggle
Param | Type | Description |
---|---|---|
target | string |
Word to search for in the board. |
done | containsCallback |
Callback to run when done verifying. |
function
Boggle~solveCallback : Callback to run when done solving.
Kind: inner typedef of Boggle
Param | Type | Description |
---|---|---|
words | array |
Array of the words in the board. |
function
Boggle~containsCallback : Callback to run when done verifying.
Kind: inner typedef of Boggle
Param | Type | Description |
---|---|---|
found | boolean |
Whether or not the word was found in the board. |