Calc Invoices to Pay?

Kenneth Brody kenbrody at bestweb.net
Fri Mar 7 07:13:46 PST 2008


Quoting Stanley Barnett (Thu, 6 Mar 2008 21:36:37 -0500):

>> The reason you spent a long time searching for the right combination
> and not finding
>> it is because there is no combination that matches those amounts.
>
> The little routing I'm asking for should be able to tell me that in a
> second or two, therefore saving me the wasted time I spent looking.
>
> BTW, I talked to the customer today and learned that he had split some
> invoices across the 2 payments (checks).  That's perfectly fine, but if
> I had known that from the beginning I would not have spent the time on
> it, instead I would have called him for the details.  The code I'm
> looking for should have quickly figured it out as both you and I did and
> issue a message box saying no combination could be found.
>
> How long did you spend searching for a combination?  Did you test all
> possible combinations?  And, how did you test?
[...]

Well, I was on my new laptop, which doesn't yet have filePro on it, so I
"cheated" and wrote a C program.

Since there were only 11 invoices, I simply calculated all 2048 different
combinations, and checked for the desired values.  When it didn't find any,
I had it write the sums to a file, sorted the output, and manually looked
for the desired values.  (And, of course, still didn't find them.)

Basic logic:

     Put the numbers into an array of size N.
     Loop X from 0 to 2^N-1.
         Init sum to zero.
         Loop Y from 0 to N-1.
             If bit Y is set in X, add invoice[Y] to sum.
         Check if sum is desired about.

With only 11 invoices, it only took a fraction of a second to loop through
the 2,048 combinations.  Of course, if you have 35 invoices, checking all
34,359,738,368 combinations using this method may take some time.

Total time to get the computer to tell me there were no matches found:
about 5 minutes.

Total time to manually re-check: less than 5 more minutes.

-- 
KenBrody at BestWeb dot net        spamtrap: <g8ymh8uf001 at sneakemail.com>
http://www.hvcomputer.com
http://www.fileProPlus.com


More information about the Filepro-list mailing list