NAME

Math::Permute::Array - Perl extension for computing any permutation of an array. The permutation could be access by an index in [0,cardinal] or by iterating with prev, cur and next.

SYNOPSIS

use Math::Permute::Array;

print "permutation with direct call to Permute\n";
my $i;
foreach $i (0..6){
  my @tmp = Math::Permute::Array::Permute($i,(1,2,3));
  print "@tmp\n";
}

print "permutation with counter\n";
my $p = new Math::Permute::Array((1,2,3));
my $i;
foreach $i (0..$p->cardinal()){
  my @tmp = $p->permutation($i);
  print "@tmp\n";
}

print "permutation with next\n";
my $p = new Math::Permute::Array((1,2,3));
my $i;
  my @tmp = $p->cur();
  print "@tmp\n";
foreach $i (1..$p->cardinal()){
  @tmp = $p->next();
  print "@tmp\n";
}

the output should be: permutation with direct call to Permute 1 2 3 2 1 3 3 1 2 1 3 2 2 3 1 3 2 1 1 2 3 permutation with counter 1 2 3 2 1 3 3 1 2 1 3 2 2 3 1 3 2 1 1 2 3 permutation with next 1 2 3 2 1 3 3 1 2 1 3 2 2 3 1 3 2 1 1 2 3

DESCRIPTION

This module compute the i^{th} permutation of an array recursively. The main advantage of this module is the fact that you could access to any permutation in the order that you want. Moreover this module doesn't use a lot of memory because the permutation is compute. the cost for computing one permutation is O(n).

it could be optimize by doing this iteratively but it seems efficient. Thus this module doesn't need a lot of memory because the permutation isn't stored.

EXPORT

Permute [index, @array] Returns the index^{th} permutation for the array. This function should be called directly as in the exemple.

new [@array] Returns a permutor object for the given items.

next Called on a permutor, it returns an array contening the next permutation.

prev Called on a permutor, it returns an array contening the previous permutation.

cur Called on a permutor, it returns an array contening the current permutation.

permutation [index, @array] Called on a permutor, it returns the index^{th} permutation for the array.

SEE ALSO

Math::Permute::List
Algorithm::Permute
Algorithm::FastPermute

AUTHOR

jean-noel quintin, <quintin_at___imag_dot___fr>

COPYRIGHT AND LICENSE

Copyright (C) 2012 by jean-noel quintin

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.4 or, at your option, any later version of Perl 5 you may have available.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 277:

'=item' outside of any '=over'

Around line 284:

You forgot a '=back' before '=head1'