I'm trying to see how fast i can suck up the words in /usr/share/dict/words
and take a command line arg of a word use all its permutations and find all
matches as fast as possible. Here is what i have so far.
var fs = require('fs');
var itertools = require("itertools");
var words = new Object();
var real_words = new Object();
fs.readFile('/usr/share/dict/words', function(err, data) {
var infile = data.toString().toLowerCase().split("\n");
for(i = infile.length -1;i>=0;i--) {
words[infile[i]] = true;
}
for(x= process.argv[2].length -1;x>=0;x--){
var perms = itertools.permutationsSync(process.argv[2], x+1);
for(y=perms.length -1;y>=0;y--){
var try_word = perms[y]
real_word = try_word.join('');
if(words[real_word]){
real_words[real_word] = true;
}
}
}
console.log(Object.keys(real_words).length);
});
╰─$ time node words.js racecardss
168
18.90s user 1.02s system 100% cpu 19.758 total
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.