in reply to Recursion problem
Not that this is going to help you, but here is naive approach using modules available from CPAN. The idea is simply to iterate through all the subsets of the values finding those which satisfy the summation constraint.
use Algorithm::Combinatorics qw(subsets); use List::Util qw(sum); my @data = (5, -6, 8, 10, 12, 3, 10); my $iter = subsets(\@data); while (my $subset = $item->next) { if (sum(@$subset) == 21) { print "found a solution: @$subset\n" } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Recursion problem
by someone202 (Initiate) on May 25, 2008 at 08:17 UTC | |
by pc88mxer (Vicar) on May 25, 2008 at 09:07 UTC |