This is a C++17 demonstration of a method of generating an output set of unique combinations when given an input set of vectors containing arbitrary values.
Integer Source: ========================================
Printing 4 vectors numbered 0..3
0: (1)
1: (2, 3, 4)
2: (5, 6)
3: (7)
===================================================
Generated Integer Result: ========================================
Printing 6 vectors numbered 0..5
0: (1, 2, 5, 7)
1: (1, 3, 5, 7)
2: (1, 4, 5, 7)
3: (1, 2, 6, 7)
4: (1, 3, 6, 7)
5: (1, 4, 6, 7)
===================================================
Sorted Integer Result: ========================================
Printing 6 vectors numbered 0..5
0: (1, 2, 5, 7)
1: (1, 2, 6, 7)
2: (1, 3, 5, 7)
3: (1, 3, 6, 7)
4: (1, 4, 5, 7)
5: (1, 4, 6, 7)
===================================================
String Source: ========================================
Printing 5 vectors numbered 0..4
0: (alpha)
1: (beta, gamma, delta)
2: (zeta, eta, theta, iota, kappa, lambda, mu, nu, xi, omicron, pi, rho, sigma, tau, upsilon)
3: (phi, chi)
4: (psi, omega)
===================================================
String Result: ========================================
Printing 180 vectors numbered 0..179
0: (alpha, beta, zeta, phi, psi)
1: (alpha, gamma, zeta, phi, psi)
2: (alpha, delta, zeta, phi, psi)
3: (alpha, beta, eta, phi, psi)
4: (alpha, gamma, eta, phi, psi)
5: (alpha, delta, eta, phi, psi)
6: (alpha, beta, theta, phi, psi)
7: (alpha, gamma, theta, phi, psi)
8: (alpha, delta, theta, phi, psi)
9: (alpha, beta, iota, phi, psi)
10: (alpha, gamma, iota, phi, psi)
11: (alpha, delta, iota, phi, psi)
12: (alpha, beta, kappa, phi, psi)
13: (alpha, gamma, kappa, phi, psi)
14: (alpha, delta, kappa, phi, psi)
15: (alpha, beta, lambda, phi, psi)
16: (alpha, gamma, lambda, phi, psi)
17: (alpha, delta, lambda, phi, psi)
18: (alpha, beta, mu, phi, psi)
19: (alpha, gamma, mu, phi, psi)
20: (alpha, delta, mu, phi, psi)
21: (alpha, beta, nu, phi, psi)
22: (alpha, gamma, nu, phi, psi)
23: (alpha, delta, nu, phi, psi)
24: (alpha, beta, xi, phi, psi)
25: (alpha, gamma, xi, phi, psi)
26: (alpha, delta, xi, phi, psi)
27: (alpha, beta, omicron, phi, psi)
28: (alpha, gamma, omicron, phi, psi)
29: (alpha, delta, omicron, phi, psi)
30: (alpha, beta, pi, phi, psi)
31: (alpha, gamma, pi, phi, psi)
32: (alpha, delta, pi, phi, psi)
33: (alpha, beta, rho, phi, psi)
34: (alpha, gamma, rho, phi, psi)
35: (alpha, delta, rho, phi, psi)
36: (alpha, beta, sigma, phi, psi)
37: (alpha, gamma, sigma, phi, psi)
38: (alpha, delta, sigma, phi, psi)
39: (alpha, beta, tau, phi, psi)
40: (alpha, gamma, tau, phi, psi)
41: (alpha, delta, tau, phi, psi)
42: (alpha, beta, upsilon, phi, psi)
43: (alpha, gamma, upsilon, phi, psi)
44: (alpha, delta, upsilon, phi, psi)
45: (alpha, beta, zeta, chi, psi)
46: (alpha, gamma, zeta, chi, psi)
47: (alpha, delta, zeta, chi, psi)
48: (alpha, beta, eta, chi, psi)
49: (alpha, gamma, eta, chi, psi)
50: (alpha, delta, eta, chi, psi)
51: (alpha, beta, theta, chi, psi)
52: (alpha, gamma, theta, chi, psi)
53: (alpha, delta, theta, chi, psi)
54: (alpha, beta, iota, chi, psi)
55: (alpha, gamma, iota, chi, psi)
56: (alpha, delta, iota, chi, psi)
57: (alpha, beta, kappa, chi, psi)
58: (alpha, gamma, kappa, chi, psi)
59: (alpha, delta, kappa, chi, psi)
60: (alpha, beta, lambda, chi, psi)
61: (alpha, gamma, lambda, chi, psi)
62: (alpha, delta, lambda, chi, psi)
63: (alpha, beta, mu, chi, psi)
64: (alpha, gamma, mu, chi, psi)
65: (alpha, delta, mu, chi, psi)
66: (alpha, beta, nu, chi, psi)
67: (alpha, gamma, nu, chi, psi)
68: (alpha, delta, nu, chi, psi)
69: (alpha, beta, xi, chi, psi)
70: (alpha, gamma, xi, chi, psi)
71: (alpha, delta, xi, chi, psi)
72: (alpha, beta, omicron, chi, psi)
73: (alpha, gamma, omicron, chi, psi)
74: (alpha, delta, omicron, chi, psi)
75: (alpha, beta, pi, chi, psi)
76: (alpha, gamma, pi, chi, psi)
77: (alpha, delta, pi, chi, psi)
78: (alpha, beta, rho, chi, psi)
79: (alpha, gamma, rho, chi, psi)
80: (alpha, delta, rho, chi, psi)
81: (alpha, beta, sigma, chi, psi)
82: (alpha, gamma, sigma, chi, psi)
83: (alpha, delta, sigma, chi, psi)
84: (alpha, beta, tau, chi, psi)
85: (alpha, gamma, tau, chi, psi)
86: (alpha, delta, tau, chi, psi)
87: (alpha, beta, upsilon, chi, psi)
88: (alpha, gamma, upsilon, chi, psi)
89: (alpha, delta, upsilon, chi, psi)
90: (alpha, beta, zeta, phi, omega)
91: (alpha, gamma, zeta, phi, omega)
92: (alpha, delta, zeta, phi, omega)
93: (alpha, beta, eta, phi, omega)
94: (alpha, gamma, eta, phi, omega)
95: (alpha, delta, eta, phi, omega)
96: (alpha, beta, theta, phi, omega)
97: (alpha, gamma, theta, phi, omega)
98: (alpha, delta, theta, phi, omega)
99: (alpha, beta, iota, phi, omega)
100: (alpha, gamma, iota, phi, omega)
101: (alpha, delta, iota, phi, omega)
102: (alpha, beta, kappa, phi, omega)
103: (alpha, gamma, kappa, phi, omega)
104: (alpha, delta, kappa, phi, omega)
105: (alpha, beta, lambda, phi, omega)
106: (alpha, gamma, lambda, phi, omega)
107: (alpha, delta, lambda, phi, omega)
108: (alpha, beta, mu, phi, omega)
109: (alpha, gamma, mu, phi, omega)
110: (alpha, delta, mu, phi, omega)
111: (alpha, beta, nu, phi, omega)
112: (alpha, gamma, nu, phi, omega)
113: (alpha, delta, nu, phi, omega)
114: (alpha, beta, xi, phi, omega)
115: (alpha, gamma, xi, phi, omega)
116: (alpha, delta, xi, phi, omega)
117: (alpha, beta, omicron, phi, omega)
118: (alpha, gamma, omicron, phi, omega)
119: (alpha, delta, omicron, phi, omega)
120: (alpha, beta, pi, phi, omega)
121: (alpha, gamma, pi, phi, omega)
122: (alpha, delta, pi, phi, omega)
123: (alpha, beta, rho, phi, omega)
124: (alpha, gamma, rho, phi, omega)
125: (alpha, delta, rho, phi, omega)
126: (alpha, beta, sigma, phi, omega)
127: (alpha, gamma, sigma, phi, omega)
128: (alpha, delta, sigma, phi, omega)
129: (alpha, beta, tau, phi, omega)
130: (alpha, gamma, tau, phi, omega)
131: (alpha, delta, tau, phi, omega)
132: (alpha, beta, upsilon, phi, omega)
133: (alpha, gamma, upsilon, phi, omega)
134: (alpha, delta, upsilon, phi, omega)
135: (alpha, beta, zeta, chi, omega)
136: (alpha, gamma, zeta, chi, omega)
137: (alpha, delta, zeta, chi, omega)
138: (alpha, beta, eta, chi, omega)
139: (alpha, gamma, eta, chi, omega)
140: (alpha, delta, eta, chi, omega)
141: (alpha, beta, theta, chi, omega)
142: (alpha, gamma, theta, chi, omega)
143: (alpha, delta, theta, chi, omega)
144: (alpha, beta, iota, chi, omega)
145: (alpha, gamma, iota, chi, omega)
146: (alpha, delta, iota, chi, omega)
147: (alpha, beta, kappa, chi, omega)
148: (alpha, gamma, kappa, chi, omega)
149: (alpha, delta, kappa, chi, omega)
150: (alpha, beta, lambda, chi, omega)
151: (alpha, gamma, lambda, chi, omega)
152: (alpha, delta, lambda, chi, omega)
153: (alpha, beta, mu, chi, omega)
154: (alpha, gamma, mu, chi, omega)
155: (alpha, delta, mu, chi, omega)
156: (alpha, beta, nu, chi, omega)
157: (alpha, gamma, nu, chi, omega)
158: (alpha, delta, nu, chi, omega)
159: (alpha, beta, xi, chi, omega)
160: (alpha, gamma, xi, chi, omega)
161: (alpha, delta, xi, chi, omega)
162: (alpha, beta, omicron, chi, omega)
163: (alpha, gamma, omicron, chi, omega)
164: (alpha, delta, omicron, chi, omega)
165: (alpha, beta, pi, chi, omega)
166: (alpha, gamma, pi, chi, omega)
167: (alpha, delta, pi, chi, omega)
168: (alpha, beta, rho, chi, omega)
169: (alpha, gamma, rho, chi, omega)
170: (alpha, delta, rho, chi, omega)
171: (alpha, beta, sigma, chi, omega)
172: (alpha, gamma, sigma, chi, omega)
173: (alpha, delta, sigma, chi, omega)
174: (alpha, beta, tau, chi, omega)
175: (alpha, gamma, tau, chi, omega)
176: (alpha, delta, tau, chi, omega)
177: (alpha, beta, upsilon, chi, omega)
178: (alpha, gamma, upsilon, chi, omega)
179: (alpha, delta, upsilon, chi, omega)
===================================================
Sorted String Result: ========================================
Printing 180 vectors numbered 0..179
0: (alpha, beta, eta, chi, omega)
1: (alpha, beta, eta, chi, psi)
2: (alpha, beta, eta, phi, omega)
3: (alpha, beta, eta, phi, psi)
4: (alpha, beta, iota, chi, omega)
5: (alpha, beta, iota, chi, psi)
6: (alpha, beta, iota, phi, omega)
7: (alpha, beta, iota, phi, psi)
8: (alpha, beta, kappa, chi, omega)
9: (alpha, beta, kappa, chi, psi)
10: (alpha, beta, kappa, phi, omega)
11: (alpha, beta, kappa, phi, psi)
12: (alpha, beta, lambda, chi, omega)
13: (alpha, beta, lambda, chi, psi)
14: (alpha, beta, lambda, phi, omega)
15: (alpha, beta, lambda, phi, psi)
16: (alpha, beta, mu, chi, omega)
17: (alpha, beta, mu, chi, psi)
18: (alpha, beta, mu, phi, omega)
19: (alpha, beta, mu, phi, psi)
20: (alpha, beta, nu, chi, omega)
21: (alpha, beta, nu, chi, psi)
22: (alpha, beta, nu, phi, omega)
23: (alpha, beta, nu, phi, psi)
24: (alpha, beta, omicron, chi, omega)
25: (alpha, beta, omicron, chi, psi)
26: (alpha, beta, omicron, phi, omega)
27: (alpha, beta, omicron, phi, psi)
28: (alpha, beta, pi, chi, omega)
29: (alpha, beta, pi, chi, psi)
30: (alpha, beta, pi, phi, omega)
31: (alpha, beta, pi, phi, psi)
32: (alpha, beta, rho, chi, omega)
33: (alpha, beta, rho, chi, psi)
34: (alpha, beta, rho, phi, omega)
35: (alpha, beta, rho, phi, psi)
36: (alpha, beta, sigma, chi, omega)
37: (alpha, beta, sigma, chi, psi)
38: (alpha, beta, sigma, phi, omega)
39: (alpha, beta, sigma, phi, psi)
40: (alpha, beta, tau, chi, omega)
41: (alpha, beta, tau, chi, psi)
42: (alpha, beta, tau, phi, omega)
43: (alpha, beta, tau, phi, psi)
44: (alpha, beta, theta, chi, omega)
45: (alpha, beta, theta, chi, psi)
46: (alpha, beta, theta, phi, omega)
47: (alpha, beta, theta, phi, psi)
48: (alpha, beta, upsilon, chi, omega)
49: (alpha, beta, upsilon, chi, psi)
50: (alpha, beta, upsilon, phi, omega)
51: (alpha, beta, upsilon, phi, psi)
52: (alpha, beta, xi, chi, omega)
53: (alpha, beta, xi, chi, psi)
54: (alpha, beta, xi, phi, omega)
55: (alpha, beta, xi, phi, psi)
56: (alpha, beta, zeta, chi, omega)
57: (alpha, beta, zeta, chi, psi)
58: (alpha, beta, zeta, phi, omega)
59: (alpha, beta, zeta, phi, psi)
60: (alpha, delta, eta, chi, omega)
61: (alpha, delta, eta, chi, psi)
62: (alpha, delta, eta, phi, omega)
63: (alpha, delta, eta, phi, psi)
64: (alpha, delta, iota, chi, omega)
65: (alpha, delta, iota, chi, psi)
66: (alpha, delta, iota, phi, omega)
67: (alpha, delta, iota, phi, psi)
68: (alpha, delta, kappa, chi, omega)
69: (alpha, delta, kappa, chi, psi)
70: (alpha, delta, kappa, phi, omega)
71: (alpha, delta, kappa, phi, psi)
72: (alpha, delta, lambda, chi, omega)
73: (alpha, delta, lambda, chi, psi)
74: (alpha, delta, lambda, phi, omega)
75: (alpha, delta, lambda, phi, psi)
76: (alpha, delta, mu, chi, omega)
77: (alpha, delta, mu, chi, psi)
78: (alpha, delta, mu, phi, omega)
79: (alpha, delta, mu, phi, psi)
80: (alpha, delta, nu, chi, omega)
81: (alpha, delta, nu, chi, psi)
82: (alpha, delta, nu, phi, omega)
83: (alpha, delta, nu, phi, psi)
84: (alpha, delta, omicron, chi, omega)
85: (alpha, delta, omicron, chi, psi)
86: (alpha, delta, omicron, phi, omega)
87: (alpha, delta, omicron, phi, psi)
88: (alpha, delta, pi, chi, omega)
89: (alpha, delta, pi, chi, psi)
90: (alpha, delta, pi, phi, omega)
91: (alpha, delta, pi, phi, psi)
92: (alpha, delta, rho, chi, omega)
93: (alpha, delta, rho, chi, psi)
94: (alpha, delta, rho, phi, omega)
95: (alpha, delta, rho, phi, psi)
96: (alpha, delta, sigma, chi, omega)
97: (alpha, delta, sigma, chi, psi)
98: (alpha, delta, sigma, phi, omega)
99: (alpha, delta, sigma, phi, psi)
100: (alpha, delta, tau, chi, omega)
101: (alpha, delta, tau, chi, psi)
102: (alpha, delta, tau, phi, omega)
103: (alpha, delta, tau, phi, psi)
104: (alpha, delta, theta, chi, omega)
105: (alpha, delta, theta, chi, psi)
106: (alpha, delta, theta, phi, omega)
107: (alpha, delta, theta, phi, psi)
108: (alpha, delta, upsilon, chi, omega)
109: (alpha, delta, upsilon, chi, psi)
110: (alpha, delta, upsilon, phi, omega)
111: (alpha, delta, upsilon, phi, psi)
112: (alpha, delta, xi, chi, omega)
113: (alpha, delta, xi, chi, psi)
114: (alpha, delta, xi, phi, omega)
115: (alpha, delta, xi, phi, psi)
116: (alpha, delta, zeta, chi, omega)
117: (alpha, delta, zeta, chi, psi)
118: (alpha, delta, zeta, phi, omega)
119: (alpha, delta, zeta, phi, psi)
120: (alpha, gamma, eta, chi, omega)
121: (alpha, gamma, eta, chi, psi)
122: (alpha, gamma, eta, phi, omega)
123: (alpha, gamma, eta, phi, psi)
124: (alpha, gamma, iota, chi, omega)
125: (alpha, gamma, iota, chi, psi)
126: (alpha, gamma, iota, phi, omega)
127: (alpha, gamma, iota, phi, psi)
128: (alpha, gamma, kappa, chi, omega)
129: (alpha, gamma, kappa, chi, psi)
130: (alpha, gamma, kappa, phi, omega)
131: (alpha, gamma, kappa, phi, psi)
132: (alpha, gamma, lambda, chi, omega)
133: (alpha, gamma, lambda, chi, psi)
134: (alpha, gamma, lambda, phi, omega)
135: (alpha, gamma, lambda, phi, psi)
136: (alpha, gamma, mu, chi, omega)
137: (alpha, gamma, mu, chi, psi)
138: (alpha, gamma, mu, phi, omega)
139: (alpha, gamma, mu, phi, psi)
140: (alpha, gamma, nu, chi, omega)
141: (alpha, gamma, nu, chi, psi)
142: (alpha, gamma, nu, phi, omega)
143: (alpha, gamma, nu, phi, psi)
144: (alpha, gamma, omicron, chi, omega)
145: (alpha, gamma, omicron, chi, psi)
146: (alpha, gamma, omicron, phi, omega)
147: (alpha, gamma, omicron, phi, psi)
148: (alpha, gamma, pi, chi, omega)
149: (alpha, gamma, pi, chi, psi)
150: (alpha, gamma, pi, phi, omega)
151: (alpha, gamma, pi, phi, psi)
152: (alpha, gamma, rho, chi, omega)
153: (alpha, gamma, rho, chi, psi)
154: (alpha, gamma, rho, phi, omega)
155: (alpha, gamma, rho, phi, psi)
156: (alpha, gamma, sigma, chi, omega)
157: (alpha, gamma, sigma, chi, psi)
158: (alpha, gamma, sigma, phi, omega)
159: (alpha, gamma, sigma, phi, psi)
160: (alpha, gamma, tau, chi, omega)
161: (alpha, gamma, tau, chi, psi)
162: (alpha, gamma, tau, phi, omega)
163: (alpha, gamma, tau, phi, psi)
164: (alpha, gamma, theta, chi, omega)
165: (alpha, gamma, theta, chi, psi)
166: (alpha, gamma, theta, phi, omega)
167: (alpha, gamma, theta, phi, psi)
168: (alpha, gamma, upsilon, chi, omega)
169: (alpha, gamma, upsilon, chi, psi)
170: (alpha, gamma, upsilon, phi, omega)
171: (alpha, gamma, upsilon, phi, psi)
172: (alpha, gamma, xi, chi, omega)
173: (alpha, gamma, xi, chi, psi)
174: (alpha, gamma, xi, phi, omega)
175: (alpha, gamma, xi, phi, psi)
176: (alpha, gamma, zeta, chi, omega)
177: (alpha, gamma, zeta, chi, psi)
178: (alpha, gamma, zeta, phi, omega)
179: (alpha, gamma, zeta, phi, psi)
===================================================
All of the input vector<T>
supplied to the function ...
template<typename T> CVector<T> &combinations(const CVector<T> &v, CVector<T> &dest)
... Must be of length 1 or greater, i.e., the count of the output vector(s) will be zero if any of the input vectors length is zero.
Why? Because the the count of the output vectors is the product of the lengths of the input vectors.
This also guards against divide-by-zero exceptions in the combinations
function
- I used
vector<vector<T>>
here for theCVector
definition: A more optimal execution time might be acheived by usingvector<shared_ptr<vector<shared_ptr<T>>>
at the expense of more heap overhead.