Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Mathematics knundrum
Message
De
24/04/2003 14:59:46
 
 
À
24/04/2003 14:42:13
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00780672
Message ID:
00781254
Vues:
52
Steve --

The algorithm I suggested is the dumbest and most brute force approach, which compares all possible combinations.

There may be ways to eliminate values. Certainly, an initial test should determine if the sum of all is less than the target value. In that case, there are no solutions. As you mention, one could also short circuit a sum if it is already greater, and that could be easily implemented. But, there's a cost for the comparison on every add operation.

Another approach involves analysis of the data set. Ordering the data and comparing the data profile to the target value will give significant info. The highest values would indicate the minimum number of values which would need to reach the target. The lowest values would indicate the maximum number of values to reach the target. Depending on the data profile and target, this could reduce significantly the comparisons. A new algorithm would probably be needed to implement this.

If Marvin only needs to know whether or not one exists, and the composition, there are other approaches. I'd take the ordered set, algorithmically find a base from the maximums, then try to reach the goal through adding minimums.

These are just some educated guesses. I haven't really done much in this area.

Maybe that quantuum computer would come in handy right about now...(g)

Jay



>I was trying to think of a way to short circuit the loops once the sum of a group of numbers exceeds the target value...
>
>And if the numbers are sorted numerically, there is no reason to start a loop for any numbers greater than half of the target value. But of course, if there is a solution, it would be found by that time.
>
>But I haven't studied Jay's algorithm, so I don't know how this could be implemented...
>
>Any thoughts, Jay?
>
>>Hi Steve, no negative numbers. Actually the first thing I do is delete all records less than or equal to 0 and all numbers greater than the Target to help narrow the field. -Marvin
>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform