permutation

Downloadpermutation(set,subset)   Returns the number of unique subsets created from all permutations of the given number of elements in which the order of the chosen elements is significant.
/*
**  Usage:
**      permutation(set,subset)
**
**  Arguments:
**      set         number of elements, integer
**      subset      size of the subset, integer
**
**  Returns:
**      the number of unique subsets created from all
**      permutations of the given number of elements in
**      which the order of the chosen elements is significant,
**      or (-1) on error.
**
**  Example:
**      If six Olympic runners compete in a race, the number of
**      possible medalist rankings equals permutation(6,3) or 120
**
**  GMLscripts.com
*/

{
    var f,k,l,m,n;
    n = floor(argument0);
    k = floor(argument1);
    m = n - k;
    if (m < 0) return (-1);
    else {
        f = 1;
        for (l=n; l>m; l-=1) f *= l;
        return f;
    }
}

Click if you've used this script[Please Login]
Projects: 2

 Contributor: xot


comments powered by Disqus