Disposition - library for Combinatorics

English - Spanish

Disposition is a library designed for generate permutations and combinations of elements, usual topics in combinatorial mathematics, and make easy for you to include them in your program.

The library is written in ANSI C and is released under the GPL license. You can download the last version of the program from the page of the project Disposition at SourceForge.

Disposition comes with a sample program, called disp, to demonstrate an application of the library in the generation of text strings:

$ disp
`disp' prints permutations and combinations of characters.

Usage: disp [-v|-r] TYPE CHARLIST [SIZE]

TYPE must be one of these: -p|-pr|-c|-cr|-prr|-crr
By default, the SIZE number is equal to the length of CHARLIST.

-p        Permutations (nPk)
-pr       Permutations with repetition (nPRk)
-c        Combinations (nCk)
-cr       Combinations with repetition (nCRk)
-prr      Permutations with "restricted" repetition
-crr      Combinations with "restricted" repetition
CHARLIST  string with the n characters used in the dispositions
SIZE      length k of every disposition, equal to n by default
-v        output in reverse order
-r        print only random dispositions

For Permutations and Combinations with "restricted" repetition,
characters in CHARLIST can be repeated to set the maximum number
of times that each character can appear in the dispositions.

The following table shows different sequences generated with the program disp:

$ disp -p abc
abc
acb
bac
bca
cab
cba
$ disp -pr 01 4
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
$ disp -c aeiou 3
aei
aeo
aeu
aio
aiu
aou
eio
eiu
eou
iou
$ disp -v -cr ABC 4
CCCC
BCCC
BBCC
BBBC
BBBB
ACCC
ABCC
ABBC
ABBB
AACC
AABC
AABB
AAAC
AAAB
AAAA

This is an example of program using the library to generate the permutations of 5 elements and size 3, and print them:

#include "permutation.h"
#include <stdio.h>
int main(void)
{
        Permutation *perm;
        int numelem, size, i;
        perm = newPermutation(numelem = 5, size = 3, NULL);
        if (!perm) return 1;
        disp_first(perm);
        do {
                for (i = 0; i < disp_size(perm); i++)
                        printf("%d ", disp_vec(perm)[i]);
                printf("\n");
        } while (disp_next(perm));
        disp_delete(perm);
        return 0;
}

You can find more information inside the package. For any suggestions, bugs or ideas about this software, please mail me to: jasampler at yahoo dot es