first commit
This commit is contained in:
25
perl/Examples/Chap5/make-partition-1
Normal file
25
perl/Examples/Chap5/make-partition-1
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
|
||||
###
|
||||
### make_partition
|
||||
###
|
||||
|
||||
## Chapter 5 section 2
|
||||
|
||||
sub make_partition {
|
||||
my $n = shift;
|
||||
my @agenda = [$n];
|
||||
return Iterator {
|
||||
while (@agenda) {
|
||||
my $item = pop @agenda;
|
||||
my ($largest, @rest) = @$item;
|
||||
my $min = $rest[0] || 1;
|
||||
my $max = int($largest/2);
|
||||
for ($min .. $max) {
|
||||
push @agenda, [$largest-$_, $_, @rest];
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
return;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user