10 std::cout <<
"Permutations: " << comb_obj.
permutation(n, r) << std::endl;
11 std::cout <<
"Combinations: " << comb_obj.
combination(n, r) << std::endl;
12 std::cout <<
"Binomial Coefficient: " << comb_obj.
binom_coeff(n, r)
14 std::cout <<
"Factorial: " << comb_obj.
factorial(n) << std::endl;
16 std::vector<int> vec = {1, 2, 3};
17 std::vector<std::vector<int>> perms = comb_obj.
permutations(vec);
18 std::cout <<
"Permutations of {1, 2, 3}:" << std::endl;
19 for (
const auto &perm : perms) {
21 std::cout << x <<
" ";
23 std::cout << std::endl;
26 std::vector<std::vector<int>> combs = comb_obj.
combinations(vec, r);
27 std::cout <<
"Combinations of size " << r
28 <<
" from {1, 2, 3}:" << std::endl;
29 for (
const auto &comb : combs) {
31 std::cout << x <<
" ";
33 std::cout << std::endl;
36 std::cout <<
"Partitions of " << n <<
":" << std::endl;
37 std::vector<std::vector<int>> partitions = comb_obj.
partitions(n);
38 for (
const auto &partition : partitions) {
39 for (
int x : partition) {
40 std::cout << x <<
" ";
42 std::cout << std::endl;
45 std::cout <<
"Bell numbers up to " << n <<
":" << std::endl;
46 std::vector<int64_t> bell = comb_obj.
bell_num(n);
47 for (
int i = 0; i <= n; ++i) {
48 std::cout <<
"B(" << i <<
") = " << bell[i] << std::endl;
51 std::cout <<
"Stirling numbers of the second kind (S(5, 3)): "
54 std::cout <<
"Gray code of length 3:" << std::endl;
55 std::vector<int> gray = comb_obj.
gray_code(3);
57 std::cout << x <<
" ";
59 std::cout << std::endl;
61 std::cout <<
"Number of derangements for n=5: " << comb_obj.
subfactorial(5)
64 std::cout <<
"Number of increasing subsequences of length 2 in a "
65 "permutation of length 5: "
68 std::cout <<
"Partitions of " << n <<
" using distinct parts:" << std::endl;
69 std::vector<std::vector<int>> partition_distinct =
71 for (
const auto &partition : partition_distinct) {
72 for (
int x : partition) {
73 std::cout << x <<
" ";
75 std::cout << std::endl;
78 std::cout <<
"Compositions of " << n <<
":" << std::endl;
79 std::vector<std::vector<int>> compositions = comb_obj.
compositions(n);
80 for (
const auto &composition : compositions) {
81 for (
int x : composition) {
82 std::cout << x <<
" ";
84 std::cout << std::endl;
87 std::cout <<
"Number of Dyck words of length 10: " << comb_obj.
dyck_words(5)
90 std::cout <<
"Dyck words of length 2 * 3:" << std::endl;
92 for (
const auto &word : dyck_words) {
93 std::cout << word << std::endl;
96 std::cout <<
"Number of necklaces with 4 beads of 2 different colors: "
99 std::cout <<
"Necklaces with 4 beads of 2 different colors:" << std::endl;
101 for (
const auto &necklace : necklaces) {
102 for (
int color : necklace) {
103 std::cout << color <<
" ";
105 std::cout << std::endl;
108 std::cout <<
"Number of Lyndon words of length 3: "
111 std::cout <<
"Lyndon words of length 3:" << std::endl;
113 for (
const auto &word : lyndonWords) {
114 std::cout << word << std::endl;
A class providing various combinatorial functions and algorithms.
int64_t subfactorial(int n)
Calculate the subfactorial (!n) or derangement of n.
int64_t necklaces(int n, int k)
Calculate the number of necklaces of length n with k colors.
int64_t lyndonWords(int n)
Calculate the number of Lyndon words of length n.
std::vector< int64_t > bell_num(int n)
Calculate the Bell numbers.
int64_t dyck_words(int n)
Calculate the number of Dyck words of length 2n.
int64_t binom_coeff(int n, int r)
Calculate the binomial coefficient (n choose r)
int64_t factorial(int n)
Calculate the factorial of a number.
std::vector< std::vector< int > > partitions(int n)
Generate all partitions of a positive integer n.
std::vector< int > gray_code(int n)
Generate the Gray code sequence of length n.
std::vector< std::vector< int > > partition_distinct(int n)
Generate all distinct partitions of a positive integer n.
int64_t permutation(int n, int r)
Calculate the number of permutations (nPr)
int64_t stirling_num(int n, int k)
Calculate the Stirling number of the second kind.
int64_t combination(int n, int r)
Calculate the number of combinations (nCr)
std::vector< std::vector< int > > compositions(int n)
Generate all compositions of a positive integer n.
int64_t subsequences(int n, int k)
Calculate the number of subsequences of length k from n items.
std::vector< std::vector< T > > combinations(const std::vector< T > &vec, int r)
Generate all combinations of a vector.
std::vector< std::string > generateLyndonWords(int n)
Generate all Lyndon words of length n.
std::vector< std::vector< T > > permutations(const std::vector< T > &vec)
Generate all permutations of a vector.
std::vector< std::string > gen_dyck_words_until(int n)
Generate Dyck words up to length n.
std::vector< std::vector< int > > generateNecklaces(int n, int k)
Generate all necklaces of length n with k colors.