Skip to content

Instantly share code, notes, and snippets.

@slofurno
Last active November 1, 2015 03:55
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 slofurno/ea1b01d6693e306b357c to your computer and use it in GitHub Desktop.
Save slofurno/ea1b01d6693e306b357c to your computer and use it in GitHub Desktop.
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