Created
July 30, 2014 06:07
-
-
Save afshinator/d3f1e0003ac035f3fd9c 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[add your bin description]" /> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
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 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