: can u plz elaborate a bit more..
: "
The GEEK Shall Inherit The Earth"
The algorithm is quite basic. If you want to know all the permutations of a 1 digit number, then you simply loop across that digit:
for (each digit) {
show digit
}
If you want to find the permutations of two digits, you loop across the first and for every step in that loop you loop across the second digit if it is not equal to the first:
for (first: each digit) {
for (second: each digit) {
if (second <> first)
show first+second
}
}
This process repeats itself for every additional digit in the permutation. You could create a nested loop as deep as you like, but if you want to add another, then you need to change the code.
Luckily for programmers it is possible to call a procedure from itself (recursive procedures). This allows you to dynamically nest loops one in the other. The pseudo code I gave earlier is a recursive solution for permutations.