Last active
November 1, 2015 03:55
-
-
Save slofurno/ea1b01d6693e306b357c to your computer and use it in GitHub Desktop.
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
var numbers = ["13", "01", "02", "24", "14", "12", "25"].map(x=>[].slice.call(x)).map(x=>x.concat(x.slice().reverse())).map(x=>x.join("")).map(x=>[x.substr(0,2),x.substr(-2)]); | |
var perm = function(arr){ | |
if (arr.length===1){ | |
return [arr]; | |
} | |
var results = []; | |
for(var i = 0;i<arr.length;i++){ | |
var rest = arr.slice(); | |
var d = rest.splice(i,1); | |
perm(rest).map(x=>d.concat(x)).forEach(b=>results.push(b)); | |
} | |
return results; | |
}; | |
var comb = function(arr){ | |
var results = []; | |
for(var k = 0;k<128;k++){ | |
var r = arr.map((x,i)=> x[(k>>i)&1]); | |
results.push(r); | |
} | |
return results; | |
}; | |
var a = perm(numbers).map(x=>comb(x)).reduce((a,c)=>a.concat(c)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment