57 for (
size_t i = 0; i < s.size(); ++i)
68 std::cout <<
"[1] next_permutation with duplicates (multiset)\n";
74 std::cout << std::setw(3) <<
count <<
" : ";
81 std::cout << std::setw(3) <<
count <<
" : ";
86 std::cout <<
"Total distinct lexicographic permutations: " <<
count <<
"\n";
87 std::cout <<
"After last step, reset to first: ";
94 std::cout <<
"[2] next_permutation with custom comparator (descending order)\n";
99 for (
size_t step = 1; step <= 5; ++step)
101 std::cout <<
"Step " << step <<
" -> ";
112 std::cout <<
"[3] next_combination_indices (k-combinations over [0..n))\n";
122 std::cout << std::setw(3) <<
count <<
" : ";
130 std::cout <<
"Total combinations C(" << n <<
", 3): " <<
count
131 <<
" (verified by combination_count = "
137 std::cout <<
"[4] next_combination_mask (fixed-popcount bitmask)\n";
147 std::cout << std::setw(3) <<
count <<
" : mask = ";
148 for (
size_t b = n; b > 0; --b)
149 std::cout << (((mask >> (b - 1)) & 1ULL) ?
'1' :
'0');
156 std::cout <<
"Total bitmask combinations: " <<
count <<
"\n\n";
161 std::cout <<
"[5] for_each_combination / build_combinations\n";
165 "geom",
"strings",
"graphs",
"dp",
"net"
168 std::cout <<
"Feature triplets:\n";
179 std::cout <<
"\nMaterialized pairs: " << pairs.size() <<
"\n";
180 std::cout <<
"First: ";
182 std::cout <<
" | Last: ";
198 std::cout <<
"[6] lazy_permutations (ah-comb-generators.H)\n";
202 std::cout <<
"First 5 of the 4! = 24 permutations of a, b, c, d:\n";
207 std::cout << std::setw(3) << ++
count <<
" : ";
213 std::cout <<
"\nNote: the yielded array is reused in place across steps —\n"
214 "copy it (as print_seq does implicitly, by reading before the\n"
215 "next iteration) if you need to keep more than one alive.\n\n";
220 std::cout <<
"[7] lazy_combinations (ah-comb-generators.H)\n";
224 "geom",
"strings",
"graphs",
"dp",
"net"
228 std::cout <<
"Feature triplets, driven by a range-for instead of a\n"
237 <<
" combinations, matching for_each_combination in [5].\n\n";
243 std::cout <<
"\n=== Combinatorics / Enumeration ===\n\n";
253 std::cout <<
"Done.\n";
Lazy (coroutine-based) permutation and combination enumeration.
Combinatorics utilities: permutations, combinations, and matrix transposition.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
bool for_each_combination(const Array< T > &values, const size_t k, Op &&op)
*/
Array< Array< T > > build_combinations(const Array< T > &values, const size_t k)
Materialize all k-combinations of Array<T>.
bool next_combination_indices(Array< size_t > &idx, const size_t n, const bool reset_on_last=true)
Advance an index-combination [i0 < i1 < ... < i(k-1)] to the next one.
bool next_combination_mask(uint64_t &mask, const size_t n, const bool reset_on_last=true)
Advance a fixed-popcount bitmask to the next combination (Gosper hack).
Aleph::Generator< Array< T > > lazy_permutations(Array< T > a, Compare cmp=Compare())
Lazily enumerate all permutations of a, in lexicographic order.
bool next_permutation(Array< T > &a, Compare cmp=Compare(), const bool reset_on_last=true)
Compute the next lexicographic permutation of an Array.
uint64_t first_combination_mask(const size_t k)
Build the first k-of-64 combination mask (k low bits set).
size_t combination_count(size_t n, size_t k)
Compute n choose k with overflow checks.
void print_rule()
Prints a horizontal rule for example output separation.
Aleph::Generator< Array< T > > lazy_combinations(Array< T > a, size_t k)
Lazily enumerate all k-element combinations of a's elements.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
void print_seq(const C< T > &c)