#!/usr/bin/perl -l

# permutation(n) is the number of permutations of n elements.
# permutation(n,k) is the number of permutations of k elements
#    drawn from a set of n elements.  k and n must both
#    be positive integers.
sub permutation {
    my ($n, $k) = @_;
    my $result  = 1;

    defined $k or $k = $n;
    while ( $k-- ) { $result *= $n-- }
    return $result;
}

print permutation(4);      # prints 24
print permutation(4, 2);   # prints 12
