## File: Combination-Examples.html

package info (click to toggle)
gsl-ref-html 2.3-1
• area: non-free
• in suites: bullseye, buster, sid
• size: 6,876 kB
• ctags: 4,574
• sloc: makefile: 35
 file content (135 lines) | stat: -rw-r--r-- 4,911 bytes parent folder | download
 `123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135` `````` GNU Scientific Library – Reference Manual: Combination Examples

10.7 Examples

The example program below prints all subsets of the set {0,1,2,3} ordered by size. Subsets of the same size are ordered lexicographically.

#include <stdio.h> #include <gsl/gsl_combination.h>  int  main (void)  {   gsl_combination * c;   size_t i;    printf ("All subsets of {0,1,2,3} by size:\n") ;   for (i = 0; i <= 4; i++)     {       c = gsl_combination_calloc (4, i);       do         {           printf ("{");           gsl_combination_fprintf (stdout, c, " %u");           printf (" }\n");         }       while (gsl_combination_next (c) == GSL_SUCCESS);       gsl_combination_free (c);     }    return 0; }

Here is the output from the program,

\$ ./a.out
All subsets of {0,1,2,3} by size: { } { 0 } { 1 } { 2 } { 3 } { 0 1 } { 0 2 } { 0 3 } { 1 2 } { 1 3 } { 2 3 } { 0 1 2 } { 0 1 3 } { 0 2 3 } { 1 2 3 } { 0 1 2 3 }

All 16 subsets are generated, and the subsets of each size are sorted lexicographically.

``````