Skip to content

Instantly share code, notes, and snippets.

@supersheep
Created June 30, 2013 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supersheep/5893777 to your computer and use it in GitHub Desktop.
Save supersheep/5893777 to your computer and use it in GitHub Desktop.
Exhaustive listing words
function anyequal(arr){
return arr.some(function(ei,i){
return arr.some(function(ej,j){return ej==ei && i!=j});
});
return res;
}
function getmax(wlen,len){
var max = (wlen-1).toString(wlen);
var maxarr = [];
while(maxarr.length<len)maxarr.unshift(max);
return maxarr.join("");
}
function match(words,len){
var wlen = words.length;
var results = [];
var i = 0,is,arr;
var max = getmax(wlen,len);
do{
// generate arr
is = i.toString(wlen);
arr = is.split("");
while(arr.length < len)arr.unshift('0');
// judge
if(anyequal(arr)){i++;continue;}
// get result
result = arr.map(function(num){
return words[parseInt(num,wlen)];
}).join("");
console.log(result);
results.push(result);
i++;
}while(is!=max);
}
match(["球","际","失","落","真","泰","体","星",
"国","库","谎","难","世","的","黑","言",
"吧","界","猿","山","灾","人","过","实"],4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment