forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombinatoric_examples.cpp
More file actions
63 lines (54 loc) · 1.61 KB
/
Copy pathcombinatoric_examples.cpp
File metadata and controls
63 lines (54 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <combinations.hpp>
#include <combinations_with_replacement.hpp>
#include <permutations.hpp>
#include <product.hpp>
#include <powerset.hpp>
#include <vector>
#include <string>
#include <iostream>
int main() {
const std::vector<int> v1 = {1,2,3,4,5};
std::cout << "combinations({1,2,3,4,5}, 3}:\n";
for (auto&& ns : iter::combinations(v1,3)) {
std::cout << "{ ";
for (auto&& j : ns ) {
std::cout << j << ' ';
}
std::cout << "}\n";
}
// allows elements to be used repeatedly
std::cout << "combinations_with_replacement({1, 2}, 4):\n";
std::vector<int> v2 = {1,2};
for (auto&& ns : iter::combinations_with_replacement(v2, 4)) {
std::cout << "{ ";
for (auto&& j : ns ) {
std::cout << j << ' ';
}
std::cout << "}\n";
}
std::cout << "permutations(\"abc\"):\n";
std::string s{"abc"};
for (auto&& cs : iter::permutations(s)) {
std::cout << "{ ";
for (auto&& c : cs ) {
std::cout << c << ' ';
}
std::cout << "}\n";
}
std::vector<std::string> v3 = {"abc", "def"};
std::cout << "product of three vectors (int, int, string):\n";
for (auto&& t : iter::product(v1,v2,v3)) {
std::cout << "{ "
<< std::get<0>(t) << ' '
<< std::get<1>(t) << ' '
<< std::get<2>(t) << " }\n";
}
std::cout << "powerset({1,2,3,4,5}):\n";
for (auto&& ns : iter::powerset(v1)) {
std::cout << "{ ";
for (auto&& i : ns ) {
std::cout << i << ' ';
}
std::cout << "}\n";
}
}