How about just moving the '11000000' strings into an 8-element array and
xFoot the array? If the result if 2, you've got a 2-bit number of it is 3
you've got your 3-bit numbers. 

-----Original Message-----
From: mi400-bounces@xxxxxxxxxxxx [mailto:mi400-bounces@xxxxxxxxxxxx] On
Behalf Of Dan Bale
Sent: Monday, September 20, 2004 9:42 AM
To: MI400@xxxxxxxxxxxx
Subject: [MI400] odd sort of bit-counter...

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

_______________________________________________
This is the MI Programming on the AS400 / iSeries (MI400) mailing list
To post a message email: MI400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/mi400
or email: MI400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/mi400.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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.