npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

boggle-ryan

v0.0.0-semantic-release

Published

Boggle grid solver

Downloads

3

Readme

Boggle solver

Small simple nodejs based Boggle grid solver

NPM

Build status dependencies devdependencies

semantic-release

Breaking dependencies? Dont-break using dont-break

Install and run

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.

Main logic

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);

Dependencies

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.

Testing and code complexity

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

Todo

  • Use jshint to see possible bugs
  • check dictionary initialization (is it a good idea to initialize using a sorted words array)
  • hook into trie implementation to store previous prefix query, because we keep asking for same prefix path "h - he - hel - hell - hello".

Small print

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