New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

boggle

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boggle - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

.travis.yml

10

package.json
{
"name": "boggle",
"version": "0.1.0",
"version": "0.1.1",
"description": "Boggle grid solver",

@@ -15,2 +15,7 @@ "main": "index.js",

"pre-commit": "npm test",
"pre-push": [
"rm -rf node_modules",
"npm install",
"npm test"
],
"repository": {

@@ -31,3 +36,4 @@ "type": "git",

"matrix-paths": "0.0.3",
"prefix-dictionary": "0.0.1"
"prefix-dictionary": "Zolmeister/prefix-dictionary",
"lodash": "~2.4.1"
},

@@ -34,0 +40,0 @@ "devDependencies": {

36

README.md

@@ -5,2 +5,10 @@ # Boggle solver

[![NPM][boggle-icon] ][boggle-url]
[![Build status][boggle-ci-image] ][boggle-ci-url]
[![dependencies][boggle-dependencies-image] ][boggle-dependencies-url]
[![devdependencies][boggle-devdependencies-image] ][boggle-devdependencies-url]
[![endorse][endorse-image] ][endorse-url]
## Install and run

@@ -75,2 +83,28 @@

* 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".
* 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
* [@bahmutov](https://twitter.com/bahmutov)
* [glebbahmutov.com](http://glebbahmutov.com)
* [blog](http://bahmutov.calepin.co/)
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
[boggle-icon]: https://nodei.co/npm/boggle.png?downloads=true
[boggle-url]: https://npmjs.org/package/boggle
[boggle-ci-image]: https://travis-ci.org/bahmutov/boggle.png?branch=master
[boggle-ci-url]: https://travis-ci.org/bahmutov/boggle
[boggle-dependencies-image]: https://david-dm.org/bahmutov/boggle.png
[boggle-dependencies-url]: https://david-dm.org/bahmutov/boggle
[boggle-devdependencies-image]: https://david-dm.org/bahmutov/boggle/dev-status.png
[boggle-devdependencies-url]: https://david-dm.org/bahmutov/boggle#info=devDependencies
[endorse-image]: https://api.coderwall.com/bahmutov/endorsecount.png
[endorse-url]: https://coderwall.com/bahmutov
var check = require('check-types');
var verify = check.verify;
var utils = require('./utils');
var _ = require('lodash');

@@ -31,3 +32,3 @@ var paths = require('matrix-paths').paths;

function boggleGrid(gridOfCharacters) {
utils.verifyGridOfChars(gridOfCharacters);
utils.verifyGridOfStrings(gridOfCharacters);
console.assert(gridOfCharacters.length > 0, 'empty array');

@@ -76,8 +77,40 @@

}
// support a single array as input
if (check.array(str) && (str.length === 16)) {
var grid = [
str.slice(0, 4),
str.slice(4, 8),
str.slice(8, 12),
str.slice(12, 16),
];
return boggleGrid(grid);
}
throw new Error('Invalid boggle input ' + JSON.stringify(str));
}
boggle.generate = function () {
var dice = ["AAEEGN", "ELRTTY", "AOOTTW", "ABBJOO", "EHRTVW", "CIMOTU",
"DISTTY", "EIOSST", "DELRVY", "ACHOPS", "HIMNQU", "EEINSU", "EEGHNW",
"AFFKPS", "HLNNRZ", "DEILRX"];
return _.map(_.shuffle(dice), function (die) {
var letter = _.sample(die);
return letter === 'Q' ? 'Qu' : letter;
});
};
boggle.score = function (word) {
var len = word.length;
if (len <= 2) return 0;
else if (len <= 4) return 1;
else if (len <= 5) return 2;
else if (len <= 6) return 3;
else if (len <= 7) return 5;
else return 11;
};
module.exports = {
boggle: boggle,
report: report
};
};

@@ -12,3 +12,3 @@ var boggle = require('../boggle').boggle;

gt.array(words, 'got array of words');
gt.equal(words.length, 6, 'couple of words');
gt.equal(words.length, 4, 'couple of words');
});

@@ -19,3 +19,3 @@

gt.array(words, 'got array of words');
gt.equal(words.length, 6, 'couple of words');
gt.equal(words.length, 4, 'couple of words');
});

@@ -26,3 +26,3 @@

gt.array(words, 'got array of words');
gt.equal(words.length, 6, 'couple of words');
gt.equal(words.length, 4, 'couple of words');
});

@@ -33,3 +33,3 @@

gt.array(words, 'got array of words');
gt.equal(words.length, 34, 'couple of words');
gt.equal(words.length, 18, 'couple of words');
});

@@ -40,5 +40,11 @@

gt.array(words, 'got array of words');
gt.equal(words.length, 13, 'couple of words');
gt.equal(words.length, 11, 'couple of words');
});
gt.test('Qu', function() {
var words = boggle(['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','Qu']);
gt.array(words, 'got array of words');
gt.equal(words.length, 2, 'couple of words');
});
gt.test('grid', function () {

@@ -65,2 +71,17 @@ var grid = [

}, Error, 'string is too short');
});
});
gt.test('board generation', function () {
var board = boggle.generate();
gt.array(board, 'got board array');
gt.equal(board.length, 16, 'couple of words');
});
gt.test('scoring', function() {
gt.equal(boggle.score('a'), 0, 'word score');
gt.equal(boggle.score('aaa'), 1, 'word score');
gt.equal(boggle.score('aaaaa'), 2, 'word score');
gt.equal(boggle.score('aaaaaa'), 3, 'word score');
gt.equal(boggle.score('aaaaaaa'), 5, 'word score');
gt.equal(boggle.score('aaaaaaaaaaaaa'), 11, 'word score');
});

@@ -13,2 +13,12 @@ var check = require('check-types');

function verifyGridOfStrings(grid) {
check.verify.array(grid, 'expected an Array');
console.assert(grid.every(function (row) {
return row.every(function (value) {
return check.string(value)
});
}), 'expected grid of strings');
}
function unary(fn) {

@@ -28,4 +38,5 @@ return function (a) {

verifyGridOfChars: verifyGridOfChars,
verifyGridOfStrings: verifyGridOfStrings,
unary: unary,
validWords: validWords
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc