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 = require('solve-boggle');
let boggle = new Boggle('adofhptogijrstjg');
boggle.solve(words => {
boggle.print();
console.log(words.length + ' words');
console.log(words.join(', '));
});
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 = require('solve-boggle');
let boggle1 = new Boggle('CLEINRTSHBNFAOUIEERGTPUNE');
let boggle2 = new Boggle('sdjgneraghpareugnaeporigrpeouganerkgjarpehgaeraetusnviehtvndjfgd');
let boggle3 = new Boggle(6);
let boggle4 = new Boggle(5);
let boggle5 = new Boggle();
Check for individual words in the board.
let boggle = new Boggle('eorgvregearjkgoe');
boggle.contains('grave', result => {
console.log(result);
});
boggle.contains('randomstuff', result => {
console.log(result);
});
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
new Boggle([boardParam])
Create an NxN board.
[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
boggle.contains(target, done)
Finds one English word in the board.
Kind: instance method of Boggle
target | string | Word to search for in the board. |
done | containsCallback | Callback to run when done verifying. |
Boggle~solveCallback : function
Callback to run when done solving.
Kind: inner typedef of Boggle
words | array | Array of the words in the board. |
Boggle~containsCallback : function
Callback to run when done verifying.
Kind: inner typedef of Boggle
found | boolean | Whether or not the word was found in the board. |