Math-Permute-Partitions

 view release on metacpan or  search on metacpan

lib/Math/Permute/Partitions.pm  view on Meta::CPAN

 # 2 1 4 3
  
=cut

use strict;

package Math::Permute::Partitions;
use Math::Permute::List;
use Math::Cartesian::Product;

sub permutePartitions(&@)                                                       # Generate permutations of a partitioned list
 {my $s = shift;                                                                # Subroutine to call to process each permutation

  my @p;                                                                        # Partitions 
  my $p = 0;                                                                    # Current partitions 
  for(@_)
   {permute {push @{$p[$p]}, [@_]} @$_;                                         # Permute each partition
    ++$p;
   }
  cartesian {&$s(map {@$_} @_)} @p;                                             # form cartesian product of permutations of each partition
 }



( run in 0.443 second using v1.01-cache-2.11-cpan-49f99fa48dc )