I\'m looking for an efficient way to achieve this:
you have a list of numbers 1.....n (typically: 1..5 or 1..7 or so - reasonably small, but can vary from c
Just increment a binary number and take the elements corresponding to bits that are set.
For instance, 00101101
would mean take the elements at indexes 0, 2, 3, and 5. Since your list is simply 1..n, the element is simply the index + 1.
This will generate in-order permutations. In other words, only {1, 2, 3}
will be generated. Not {1, 3, 2}
or {2, 1, 3}
or {2, 3, 1}
, etc.