71#include <tclap/CmdLine.h>
85 cout <<
"\n" << string(60,
'=') <<
"\n";
87 cout << string(60,
'=') <<
"\n\n";
98 cout << label <<
": [";
100 for (
auto it =
l.
get_it(); it.has_curr(); it.next())
103 cout << it.get_curr();
114 for (
auto it = mat.get_it(); it.has_curr(); it.next(),
row++)
118 for (
auto jt = it.get_curr().
get_it();
jt.has_curr();
jt.next())
169 cout <<
"Given lists of choices, enumerate all combinations.\n";
170 cout <<
"This is the CARTESIAN PRODUCT, not mathematical permutations.\n\n";
178 cout <<
" Colors: [rojo, azul, verde]" <<
endl;
179 cout <<
" Sizes: [S, M, L]" <<
endl;
183 cout <<
"All color-size combinations:\n";
188 for (
auto it =
perm.
get_it(); it.has_curr(); it.next())
191 cout << it.get_curr();
200 cout <<
" (3 colors × 3 sizes = 9)" <<
endl;
209 cout <<
"Binary digits: [0,1] × [0,1] × [0,1]\n";
210 cout <<
"All 3-bit binary numbers:\n";
213 for (
auto it =
perm.
get_it(); it.has_curr(); it.next())
214 cout << it.get_curr();
233 cout <<
"Two dice: [1-6] × [1-6] = 36 outcomes\n";
240 for (
auto it =
roll.
get_it(); it.has_curr(); it.next())
241 sum += it.get_curr();
248 for (
auto it =
roll.
get_it(); it.has_curr(); it.next())
249 sum += it.get_curr();
258 for (
auto it =
roll.
get_it(); it.has_curr(); it.next())
259 if (it.get_curr() <= 0)
return false;
266 for (
auto it =
roll.
get_it(); it.has_curr(); it.next())
267 sum += it.get_curr();
276 for (
auto it =
roll.
get_it(); it.has_curr(); it.next())
277 if (it.get_curr() == 0)
return true;
295 cout <<
"Lists: [1,2,3] × [10,20,30]\n\n";
302 for (
auto it =
perm.
get_it(); it.has_curr(); it.next())
303 sum += it.get_curr();
305 cout <<
" Checking: ";
307 for (
auto it =
perm.
get_it(); it.has_curr(); it.next())
310 cout << it.get_curr();
324 cout <<
"\nFound sum > 25? " << (
found ?
"yes" :
"no") <<
endl;
339 cout <<
"Values: [1,2] × [3,4]\n";
340 cout <<
"Permutations: (1,3), (1,4), (2,3), (2,4)\n\n";
347 for (
auto it =
perm.
get_it(); it.has_curr(); it.next())
353 cout <<
"\nTotal (1×3 + 1×4 + 2×3 + 2×4) = " <<
total <<
endl;
354 cout <<
"Expected: 3 + 4 + 6 + 8 = 21" <<
endl;
371 cout <<
" Bebida: [cafe, te]" <<
endl;
372 cout <<
" Comida: [arepa, empanada]" <<
endl;
383 cout <<
" " << ++n <<
": ";
384 auto&
combo = it.get_curr();
404 cout <<
"Generate all test configurations for a system.\n\n";
412 cout <<
" Build: [debug, release]" <<
endl;
413 cout <<
" Arch: [x86, x64, arm]" <<
endl;
414 cout <<
" Platform: [linux, windows]" <<
endl;
421 cout <<
" " <<
setw(2) << ++n <<
". ";
423 for (
auto it = config.
get_it(); it.has_curr(); it.next())
426 cout << it.get_curr();
436 for (
auto it = config.
get_it(); it.has_curr(); it.next())
437 if (it.get_curr() ==
"linux")
455 "Combinatorics example for Aleph-w.\n"
456 "Demonstrates transpose, permutations, and combinations.",
462 "Run only specific section: transpose, perm, predicates, "
463 "traverse, fold, build, practical, or 'all'",
464 false,
"all",
"section",
cmd
472 cout <<
"============================================================\n";
473 cout <<
" ALEPH-W COMBINATORICS EXAMPLE\n";
474 cout <<
"============================================================\n";
497 cout <<
"\n" << string(60,
'=') <<
"\n";
498 cout <<
"Combinatorics demo completed!\n";
499 cout << string(60,
'=') <<
"\n\n";
503 catch (TCLAP::ArgException& e)
505 cerr <<
"Error: " << e.error() <<
" for argument " << e.argId() <<
endl;
510 cerr <<
"Error: " << e.what() <<
endl;
Combinatorics utilities: permutations, combinations and matrix transposition.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
size_t size() const noexcept
Count the number of elements of the list.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
void print_subsection(const string &title)
void print_matrix(const string &label, const DynList< DynList< T > > &mat)
void print_section(const string &title)
void demo_perm_predicates()
void print_list(const string &label, const DynList< T > &l)
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
bool none_perm(const DynList< DynList< T > > &l, Pred &pred)
Check if no permutation satisfies a predicate.
T fold_perm(const T &init, const DynList< DynList< Tc > > &l, Op &op)
Left-fold over all permutations.
size_t perm_count(const DynList< DynList< T > > &l)
Count the total number of permutations from a list of lists.
bool traverse_perm(const DynList< DynList< T > > &l, Op &op)
Traverse all the possible permutations that can be done of a list of lists and on each permutation pe...
void for_each_perm(const DynList< DynList< T > > &l, Op &op)
Apply a procedure to every permutation produced by traverse_perm.
DynList< DynList< T > > transpose(const DynList< DynList< T > > &l)
Transpose a matrix represented as a list of lists.
T product(const Container &container, const T &init=T{1})
Compute product of all elements.
DynList< DynList< T > > build_perms(const DynList< DynList< T > > &l)
Materialize all permutations from a list of lists.
void in_place_transpose(C< C< T > > &l)
In-place transpose of a rectangular matrix stored as a nested container.
bool exists_perm(const DynList< DynList< T > > &l, Pred &pred)
Check if any permutation satisfies a predicate.
bool all_perm(const DynList< DynList< T > > &l, Pred &pred)
Check if all permutations satisfy a predicate.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.