Alan Bourke wrote:
> Let's say I have an array with an arbitrary number of rows, each 
> containing a number.
>
> I also have a target total.
>
> Would anyone have a chunk of code already that would go through each 
> combination of the numbers and output any combinations that would sum to 
> the target amount?
>
> So elements 2 and 4 might equal the total, and elements 27, 98 and 143 
> might as well.
>   
Not tested but done this sort of thing before.

nTarget = 45

for i = 1 to alen(aNumbers)-1
   for j=i+1 to alen(aNumbers)
      if aNumbers[i] + aNumbers[j] = nTarget
         ? 'Numbers ' + str(i) + str(j) + ' match target'
      endif
   next
next

Peter



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to