I'm building on code from here. I'd like to generate all permutations of a set, for example (taken from the thread):
Collection: 1, 2, 3
Permutations: {1, 2, 3}
{1, 3, 2}
{2, 1, 3}
{2, 3, 1}
{3, 1, 2}
{3, 2, 1}
There are possible permutations for every set, but this is not what I'd like to achieve. Take, for consideration, following set:
This would yield permutations, an extreme amout of
. This would take an extraordinary long time to compute, as each zero is being considered unique.
Rather than that, I'd like to only generate distinct permutations. If we do that, there are only
permutations remaining, as 18 items are identical (k).
Now, I could run the code from the mentioned thread and store the results in a HashSet, eliminating the duplicate permutations. However, that would be extremely inefficient. I'm looking for an algorithm to generate permutations with distinction directly.