ruoso has asked for the wisdom of the Perl Monks concerning the following question:
Considering
my @values = (10,40,30,14,50,29,59,20,59,20,10,1,3,5,2,4); my $wanted_sum = 291;
I need to find the best combination of @values that gives me the sum most closer to $wanted_sum.
I know brute force solves it quite easily (specially with so few items)... So the question is: Is there a way to find it without iterating on all the possible combinations?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding the best option...
by Old_Gray_Bear (Bishop) on Feb 06, 2006 at 18:18 UTC | |
by eric256 (Parson) on Feb 06, 2006 at 21:08 UTC | |
|
Re: Finding the best option...
by japhy (Canon) on Feb 06, 2006 at 17:50 UTC | |
|
Re: Finding the best option...
by saintmike (Vicar) on Feb 06, 2006 at 21:42 UTC |