I don't have anything MI related to add to this so I will keep it
short. What I have used for this type of problem works similar to a base
array-size odometer. You spin the right most value through all
combinations starting at the shortest length (one in your case) and
store the results until you get to the maximum number of values you feel
you need to test for (in this case it could be the iteration that
produces a set of values larger than your solution). As you exhaust the
right most combinations you move left and spin the right again. I have a
Java program that does this and it runs very quickly on a workstation.
The base code is fairly well optimized and will compete with C but it
has some overhead added because of the type of analysis I was trying to
perform once I found a viable solution. Speed depends on the memory
available, number of values in your array, and number of values you will
test to. 

>>> dbale@xxxxxxxxxxxxx 9/20/2004 8:42:24 AM >>>
Esteemed listers:

I have a scenario where I would like to test various combinations of
in an array and sum them to find a total amount to solve a

So, for example, I have the following array of numbers:


In this example, I am looking for any combination that adds up to
A good tool would be able to find that the 2nd, 3rd, and 5th amounts
add up
to the total amount I'm looking for.  In a real-life application, this
problem would involve an array of hundreds, if not thousands, of
usually to find a small number of amounts to sum up to the difference
to reconcile.

Joe Pluta, in a rpg400-l thread, had suggested a solution that is
workable, but I haven't figured out how to sum all of the 2-amount
combinations before I start with the 3-amount combinations.  In
essence, Joe
suggests creating an array (ARR1) loaded with all of the amounts in
list, a second array (ARR2) whose elements will contain either 1 or 0,
and a
third array (ARR3) that contains the multiplication result of the first
So, using the example above:

       ARR1  ARR2       ARR3
     185.69    0        0.00
  11,134.60    1   11,134.60
     500.03    1      500.03
   4,841.65    0        0.00
   1,500.02    1    1,500.02
     419.85    0        0.00

ARR2 would be a parsed out binary value with element 1 having the
digit, i.e. '010110' in this case.  ARR2 seems like it should be some
of a binary-calculated counter, but it isn't as easy if I'm
incrementing by
one and I want to exhaust all 2-amount combinations before I test any
3-amount combinations.  So, I would like to try utilize something

00000011 =   3
00000101 =   5
00000110 =   6
00001001 =   9
00001010 =  10
00001100 =  12
11000000 = 192 <= Highest of the 2-digit binary for 8 bits
00000111 =   7 <= The first 3-digit binary
00001011 =  11
00001101 =  13
00001110 =  14
00010011 =  19
11100000 = 224 <= Highest of the 3-digit binary for 8 bits

(Of course, I'd need as many bits as the number of amounts I'm dealing

Is there an easy way to "imcrement" like this?  I haven't been able to
my way out of this box, so if there are any "outside" thinkers, please
in.  It seems that this type of problem can't be easily solved in RPG. 
was hoping that MI has something that facilitate the type of solution
thinking of.


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.