Permutations

Hey

I am trying to generate some lists of permutations of ints but I can't make std::next_permutation work for me. The problem is I need to include permutations which don't use every number.

For example take the array of numbers [1, 2]. I need an algo that will return:

1
2
12
21

Must work with up to 8 numbers.

Anybody have any ideas?
Last edited on
The OP wants a "permutation" where it doesn't have to use each number. Their example for 12 has "permutations" of 1 2 12 21 while a permutation would have 12 21.
He just needs to think a little, right?

You do the permutations on the unique substrings.
Ah yeah, you are correct they could get all the unique substrings and use std::next_permutation on them, I thought you just mean to try it again since they tried it already :P
@frankellis: google "powerset", and then "algorithm to generate the powerset"

Topic archived. No new replies allowed.