Created
June 30, 2013 03:50
-
-
Save supersheep/5893777 to your computer and use it in GitHub Desktop.
Exhaustive listing words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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