first commit
This commit is contained in:
17
perl/Examples/Chap1/find-share
Normal file
17
perl/Examples/Chap1/find-share
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
###
|
||||
### find_share.pl
|
||||
###
|
||||
|
||||
## Chapter 1 section 8.2
|
||||
|
||||
sub find_share {
|
||||
my ($target, $treasures) = @_;
|
||||
return [] if $target == 0;
|
||||
return if $target < 0 || @$treasures == 0;
|
||||
my ($first, @rest) = @$treasures;
|
||||
my $solution = find_share($target-$first, \@rest);
|
||||
return [$first, @$solution] if $solution;
|
||||
return find_share($target , \@rest);
|
||||
}
|
||||
Reference in New Issue
Block a user