Example: I have the numbers form 1 to 10. All possible combinations, where in every combination every variable in included once without any repetition, are… well… 3628800 (10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 = 3628800).
In my case, the computer has to check ALL of the combinations, instead of picking random ones. Afterwords, the system will store the needed combinations in an array. But I can’t think of an algorithm and I can’t find one in the internet (probably because I’m not searching the right way).
What algorithm can I use for mixing a number of variables, where all of the combinations have no repeating variables?
What you are looking for is called permutations.
Wikipedia lists a few different ways:
Slow Way to get all permutations
A naive slow way involves creating a function which given an integer i, returns the ith permutation, and then just call the function N! times.
Take a look at the answer to this question here.
In-Order Way
The Lexicographic method is described as:
You should sort your sequence first to get all permutations in order.
Minimal-Swapping
May be faster, but I didn’t see any code examples on my quick look.
Consider the description of the Steinhaus-Johnson-Trotter algorithm.