I need to program all possible sets of numbers from 1
to N
for an arbitrary number m
of integers without permutation.
Since I don't know how to explain it better here are some examples:
for m = 2
vector<vector<int>> box;
int N = 5;
for(int i = 1; i <= N; i++) {
for(int j = N; j >= i; j--) {
vector<int> dummy;
dummy.push_back(i);
dummy.push_back(j);
box.push_back(dummy);
}
}
for m = 3
vector<vector<int>> box;
int N = 5;
for(int i = 1; i <= N; i++) {
for(int j = N; j >= i; j--) {
for(int k = N; k >= j; k--) {
vector<int> dummy;
dummy.push_back(i);
dummy.push_back(j);
dummy.push_back(k);
box.push_back(dummy);
}
}
}
This works perfectly fine and the result is what I need. But like already mentioned, m
can be arbitrary and I can't be bothered to implement this for m = 37
or what ever. N
and m
are known values but change while the program is running. There must be a better way to implement this than for the m = 37
case to implement a row of 37-for-loops. Can someone help me? I'm kind a clueless :\
edit: to explain better what I'm looking for here are some more examples.
Let's say N = 5
and m = 4
, than 1223
is a feasible solution for me, 124
is not since it is to short. Let's say I already found 1223
as a solution, than I don't need 2123
, 2213
or any other permutation of this number.
edit2: Or if you prefer a more visual (mathematical?) problem formulation here you go.
Consider m
the dimension. With m
been 2 you are left with a N
size Matrix. I am looking for the upper (or lower) triangle of this Matrix including the diagonal. Let's move to m = 3
, the Matrix becomes a 3 dimensional cube (or Tensor if you so wish), now I'm looking for the upper (or lower) tetrahedron including the diagonal-plain. For higher dimensions than 3 I'm looking for the hyper-tetrahedron of the hyper-cube including the hyper-diagonal-plane.