Created
August 1, 2012 04:42
-
-
Save robertpitt/3223734 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
(function(){ | |
/** | |
* Create the perms stack | |
*/ | |
var stack = []; | |
/** | |
* Declare permute functuin | |
*/ | |
function permute(pref, str) | |
{ | |
/** | |
* Set the string to an empty string of value is of negative. | |
*/ | |
var prefix = pref || ""; | |
var N = str.length; | |
/** | |
* Print out the perm | |
*/ | |
if(N == 0){ | |
stack.push(prefix) | |
return; | |
} | |
for (var i = 0; i < N; i++) | |
{ | |
permute(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, N)); | |
} | |
} | |
console.time("a"); | |
permute(null, "ABCDEFGHIJKL"); | |
console.timeEnd("a", "Permuted ABCDEF"); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment