× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Dan,

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
numbers
in an array and sum them to find a total amount to solve a
reconciliation
problem.

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

     185.69
  11,134.60
     500.03
   4,841.65
   1,500.02
     419.85
etc.

In this example, I am looking for any combination that adds up to
13,134.65.
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
amounts,
usually to find a small number of amounts to sum up to the difference
needed
to reconcile.

Joe Pluta, in a rpg400-l thread, had suggested a solution that is
somewhat
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
the
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
two.
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
                   =========
                   13,134.65

ARR2 would be a parsed out binary value with element 1 having the
low-order
digit, i.e. '010110' in this case.  ARR2 seems like it should be some
sort
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
like:

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
with.)

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

tia,
db


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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

This mailing list archive is Copyright 1997-2024 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.