Hi everyone,

This is really an algorithms question.

I want to generate a set of permutations but not in the ordinary way.

I know that I can use <algorithms> std::next_permutation to generate every single permutation of e.g. [a][b][c][d] -> a,b,c,d -> b,a,c,d ...

But what I want to do is to generate every single permutation where a permutation can include repeats e.g. [a][a][c][d] -> [a][a][a][c] -> [b][b][d][a] etc.

How can I do this?

Thanks!

This is really an algorithms question.

I want to generate a set of permutations but not in the ordinary way.

I know that I can use <algorithms> std::next_permutation to generate every single permutation of e.g. [a][b][c][d] -> a,b,c,d -> b,a,c,d ...

But what I want to do is to generate every single permutation where a permutation can include repeats e.g. [a][a][c][d] -> [a][a][a][c] -> [b][b][d][a] etc.

How can I do this?

Thanks!

If you know how to convert between numeric bases, you could enumerate all (for your example) 4-digit numbers in base-4 numeric system: (0000, 0001, 0002, 0003, 0010, ... 3333), and substitute the digits for your [a], [b], [c], and [d].

Last edited on

So I will have to use stringstream to access each element to convert it o [a][b][c][d][ etc?

Topic archived. No new replies allowed.