JavaScript Permutation Calculator and Generator:
String to
permute:
Delimiter
(permutation separator):
Use the pre-generated permutations page for more flexibility.
Here is the JavaScript source code for the permutation algorithm (from
permute.js):
var permArr = [], usedChars = [];
function permute(input) {
var i, ch, chars = input.split("");
for (i = 0; i < chars.length; i++) {
ch = chars.splice(i, 1);
usedChars.push(ch);
if (chars.length == 0) permArr[permArr.length] = usedChars.join("");
permute(chars.join(""));
chars.splice(i, 0, ch);
usedChars.pop();
}
}
You may be asking yourself, “why should I care about this?”
Permutations are often used to
solve programming problems.
Programmers often employ permutations and combinations when they want to solve a problem with
brute force.
Here's are some articles that explain good uses for permutations with examples:
Some advice to any beginning CS student unfortunate enough to be assigned the Traveling Salesman Problem...
Don't attempt to use the brute-force permutation technique for any more than about 12 cities (trust me on this, it has a big O of n factorial where n is the number of cities!)
Go to Scriptar.com Home | Alternate JS Permutation Technique | Combinations