Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

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

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

You might also like