[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## [Help-gsl] help with permutations

**From**: |
Nathan Moore |

**Subject**: |
[Help-gsl] help with permutations |

**Date**: |
Tue, 22 May 2007 08:35:11 -0500 |

Hello,
I'm working on a program which needs all possible permutations of a set of N
keys (N is obviously a small number). I cobbled together some code
(attached) this morning, but I'm guessing there's a more efficient way to
get all possible permutations of the "keys" (they are indicies to a number
of different arrays)
Any thoughts would be appreciated!
Nathan Moore
Source follows:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <gsl/gsl_permutation.h>
int
main()
{
int j, i, N = 10;
int keys[N];
gsl_permutation *s = gsl_permutation_alloc(N);
gsl_permutation_init(s);
for (j = 0; j < 5; j++) {
printf("permutation: ");
gsl_permutation_fprintf(stdout, s, " %u ");
printf("\n");
for (i = 0; i < N; i++) {
keys[i] = gsl_permutation_get(s, i);
}
printf("keys: ");
for (i = 0; i < N; i++) {
printf(" %d ", keys[i]);
}
printf("\n\n");
/* at this point I need to do a bunch of work with the keys, which are
indicies
to several other arrays */
gsl_permutation_next(s);
}
printf("\n");
return 1;
}

[Prev in Thread] |
**Current Thread** |
[Next in Thread] |

**[Help-gsl] help with permutations**,
*Nathan Moore* **<=**