Algorithm-Partition
view release on metacpan or search on metacpan
lib/Algorithm/Partition.pm view on Meta::CPAN
=cut
our $VERSION = '0.04';
=head1 SYNOPSIS
use Algorithm::Partition qw(partition);
my ($one, $two) = partition(2, 4, 1, 5, 8, 16);
unless (defined($one)) {
print "Error: $two"; # now $two is an error
} else {
print "Set 1: @$one\n";
print "Set 2: @$two\n";
}
=cut
use base qw(Exporter);
our @EXPORT_OK = qw(partition);
lib/Algorithm/Partition.pm view on Meta::CPAN
my (@one, @two);
for (my ($i, $j) = (@set - 1, $size); $i >= 0; --$i) {
if (LEFT == $table[$i][$j][1]) {
push @one, $set[$i];
$j -= $set[$i];
} elsif (TOP == $table[$i][$j][1]) {
push @two, $set[$i];
} else {
die "Programmer error. Please report this bug.";
}
}
return (\@one, \@two);
}
=head1 AUTHOR
Dmitri Tikhonov, C<< <dtikhonov at yahoo.com> >>
( run in 0.236 second using v1.01-cache-2.11-cpan-65fba6d93b7 )