first commit

This commit is contained in:
douboer
2025-09-17 16:08:16 +08:00
parent 9395faa6b2
commit 3ff47c11d5
1318 changed files with 117477 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
###
### partition-it
###
## Chapter 5 section 1.1
sub make_partitioner {
my ($n, $treasures) = @_;
my @todo = [$n, $treasures, []];
sub {
while (@todo) {
my $cur = pop @todo;
my ($target, $pool, $share) = @$cur;
if ($target == 0) { return $share }
next if $target < 0 || @$pool == 0;
my ($first, @rest) = @$pool;
push @todo, [$target-$first, \@rest, [@$share, $first]],
[$target , \@rest, $share ];
}
return undef;
} # end of anonymous iterator function
} # end of make_partitioner