Skip to content

Instantly share code, notes, and snippets.

@guipn
Last active August 29, 2015 14:02
Show Gist options
  • Save guipn/29aabba60c2896b5a87e to your computer and use it in GitHub Desktop.
Save guipn/29aabba60c2896b5a87e to your computer and use it in GitHub Desktop.
Beat Letroca
var dict = process.argv[2],
inputLetters = process.argv[3],
words = require('fs')
.readFileSync(dict, {encoding: 'utf8'})
.toLowerCase()
.replace(/\/.+/g, '')
.split(/\r\n/);
String.prototype.isWriteableWith = function (letters) {
if (this.length === 0) {
return true;
}
if (letters.indexOf(this[0]) === -1) {
return false;
}
return this
.slice(1)
.isWriteableWith(letters.replace(this[0], ''));
};
void function () {
require('fs').writeFileSync('debug-dict.txt', words);
words
.filter(function (word) {
return word.isWriteableWith(inputLetters) && word.length > 2;
})
.sort(function (one, other) {
return other.length - one.length;
})
.forEach(function (writeableWord) {
process.stdout.write(writeableWord + '\n');
});
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment