"Bearwords" word search tool
It's alive! I threw together a web tool that finds words which use the given letters:
This alpha version is at https://bearwords-217805.appspot.com/ (until I point a combinatorium.com subdomain at it.)
All the letters in the first box must be present in the word.
If any letters are entered in the second box, the word can only use those letters in addition to the required letters.
So, for example, in Alphabears, you might want to use the first box for the tiles that will expire in the next round, and the remaining available tiles in the second input.
As you can see, this version uses no styling whatsoever. The output is limited to 100 words. Use at your own risk.
Source Code
Here's the core loop of the word search. vm.searchCap is a string containing the capitalized and sorted version of the search letters. vm.additionalCap is an array containing the capitalized and sorted version of the remaining letters, although sorting turned out to be a waste of time. Eventually I should refactor so that this algorithm doesn't refer directly to any of the Angular model variables.
This is still an inefficient look-at-every-word implementation I showed yesterday, just cleaned up a tiny bit. Because it's fast enough, I probably won't end up implementing a suffix tree lookup as had been my plan.
function isSubsequence( small, big ) {
// both are sorted arrays of characters
var i = 0; // index into small
var j = 0; // index into big
while ( i < small.length ) {
if ( j >= big.length ) {
// Ran out of big before finding all the letters in small.
return false;
} else if ( small[i] == big[j] ) {
i += 1;
j += 1;
} else if ( small[i] > big[j] ) {
// Might be later in the big
j += 1;
} else {
// Can't be later in big, not present.
return false;
}
}
return true;
}
vm.searchSync = function() {
var start = performance.now();
vm.words = [];
var searchLetters = Array.from( vm.searchCap );
var checkPermitted = false;
var permittedLetters = [];
if ( vm.additionalCap.length > 0 ) {
checkPermitted = true;
permittedLetters = searchLetters.concat( vm.additionalCap );
permittedLetters.sort();
}
var allWords = vm.dictionary['wordList'];
for (var w = 0; w < allWords.length; ++w) {
var word = allWords[w];
if ( searchLetters.length < word.length ) {
var wordLetters = Array.from( word );
wordLetters.sort();
if ( isSubsequence( searchLetters, wordLetters ) ) {
if ( !checkPermitted ||
isSubsequence( wordLetters, permittedLetters ) ) {
vm.words.push( word );
if ( vm.words.length > 100 ) {
break;
}
}
}
}
}
var end = performance.now();
vm.lastSearch = end - start;
}
I'll probably upload the whole project to Github eventually, but right now I didn't even rename the Angular component I created away from "hello".