Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Small simple nodejs based Boggle grid solver
Breaking dependencies? using dont-break
After installing nodejs, run:
npm install -g boggle
// ignore any warnings
boggle "ABCD EFGH IJKL MNOP"
The spaces between letters are optional, it could be single string with 16 characters. In this case, you don't need quotes:
boggle ABCDEFGHIJKLMNOP
Case does not matter, characters will be converted to lowercase.
The algorithm iterates over the 2D grid, trying to walk depth first, including diagonally, but not visiting same cell more than once. At each step, the accumulated string is checked against the dictionary. Walking stops and the algorithm backtracks to previous depth level if the string is no longer a valid word or valid word prefix.
// src/boggle.js
var uniqueWords = {};
paths(lowerCased, {
stepWhile: function (str, x, y, grid) {
if (dictionary.isWord(str)) {
// found whole word, maybe there is more!
uniqueWords[str] = true;
return true;
}
if (dictionary.isWordPrefix(str)) {
// not a word, but possible
return true;
}
}
});
var words = Object.keys(uniqueWords);
words = utils.validWords(words);
To discover paths in the letter grid, I use matrix-paths. While walking through the matrix, I use boggle prefix-dictionary that uses a trie data structure. Trie is a binary search tree that stores words in addition to children links, making word or prefix matching very quick.
To unit and function test the module, execute command
npm test
This might require installing gt testing tool globally
npm install -g gt
To see code complexity (it is very low), run command
npm run-script complexity
This might require installing jsc tool globally
npm install -g jsc
Author: Gleb Bahmutov © 2013
License: MIT - do anything with the code, but don't blame me if it does not work.
Spread the word: tweet, star on github, click endorse, etc.
Support: if you find any problems with this module, email / tweet / open issue on Github
FAQs
Boggle grid solver
The npm package boggle receives a total of 5 weekly downloads. As such, boggle popularity was classified as not popular.
We found that boggle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.