Skip to content

Instantly share code, notes, and snippets.

@afshinator
Created July 30, 2014 06:07
Show Gist options
  • Save afshinator/d3f1e0003ac035f3fd9c to your computer and use it in GitHub Desktop.
Save afshinator/d3f1e0003ac035f3fd9c to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[add your bin description]" />
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
var re = function (n, rps) {
var result = [],
rpsl;
rps = rps || [ 'rock', 'paper', 'scissors' ];
rpsl = rps.length;
var recurse = function(n) {
var localResult = [];
if ( n === 1 ) {
for ( var i=0; i < rpsl; i++ ) {
localResult[i] = [];
localResult[i].push( rps[i] );
}
} else {
var t = recurse(n-1);
var tl = t.length;
var a, b;
for (var k=0; k < tl; k++ ) {
a = t[k];
for (var i=0; i < rpsl; i++ ) {
a.push( rps[i] );
b = a.slice();
localResult.push( b );
a.pop( rps[i] );
}
}
}
return localResult;
};
result = recurse(n);
console.log(result.length);
return result;
};
var re2 = function() {
var result = [],
t = [],
rpsl;
var rps = [ 'rock', 'paper', 'scissors' ];
rpsl = rps.length;
for ( var i=0; i < 3; i++ ) {
for (var j=0; j < 3; j++ ) {
for (var k=0; k < 3 ; k++) {
t = [];
t.push( rps[i] );
t.push(rps[j] );
t.push(rps[k] );
result.push( t);
}
}
}
console.log(result.length);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment