Google Answers Logo
View Question
 
Q: Pulling a predetermined sum from a list of values ( No Answer,   4 Comments )
Question  
Subject: Pulling a predetermined sum from a list of values
Category: Science > Math
Asked by: amazons_truth-ga
List Price: $10.00
Posted: 15 Apr 2004 07:55 PDT
Expires: 15 May 2004 07:55 PDT
Question ID: 330667
This may be an accounting or programming question. 

I am looking for a computer program/method that will let me find a specific sum
within a series of numbers. For example, if I have 6.25, 10.5, 7.6,
3.4 and 5, I'd like to know which combination adds up to 17.25 (3.4,
7.6 and 6.25). It seems relatively simple and I'm looking for a way to
do this in Excel or Access, but understand that it may be too complex
for these applications.

Request for Question Clarification by mathtalk-ga on 16 Apr 2004 21:05 PDT
How many numbers will you need to be able to handle?

As the series of numbers grows in length, the problem becomes
"combinatorially" more difficult.

Also, does your application require an exact sum, or a sum accurate to
within some error tolerance?

regards, mathtalk-ga

Clarification of Question by amazons_truth-ga on 17 Apr 2004 07:10 PDT
How many numbers will you need to be able to handle?
On average, less that 20. On rare occasions it can get up to 30.

I'm using this for insurance claims analysis. In general, we have a
bill that is underpaid. I have the amount that's underpaid but need to
single out the individual charges that could add up to the amount. And
yes, in some cases, there is no solution. It does require an exact sum
but the charges that we work with are generally in increments of $.25.
Please let me know if you need any more information.

Request for Question Clarification by mathtalk-ga on 17 Apr 2004 07:44 PDT
Thanks for the prompt clarification.  If more than one solution is
possible, do you have any preference about which one is chosen?  Do
you need to know when more than one solution is possible?

Thanks, mathtalk-ga

Clarification of Question by amazons_truth-ga on 23 Apr 2004 05:32 PDT
I'm sorry for my slow response. It's very rare that more than one
solution would be possible, but, I would need to know in that case.
There is no preference as to which is chosen. I simply need to be able
to see which values were used to come up with the sum.

Request for Question Clarification by mathtalk-ga on 23 Apr 2004 12:05 PDT
Hi, amazons_truth-ga:

If at least one solution is possible, are you saying it would be
sufficient to provide one solution and a yes/no as to whether other
solutions exist?

regards, mathtalk-ga

Clarification of Question by amazons_truth-ga on 28 Apr 2004 05:33 PDT
Yes, that would be sufficient.

Request for Question Clarification by mathtalk-ga on 04 May 2004 09:01 PDT
Hi, amazons_truth-ga:

I've written a short Prolog program to solve these kinds of problems. 
Perhas you could post the values for a "real world" example, e.g. lots
of candidate cost items, so I can test how well it performs?

regards, mathtalk-ga

Clarification of Question by amazons_truth-ga on 05 May 2004 05:27 PDT
Here you are. I would be looking for what added up to $2262.50. I've
included the values with and without labels.

  562.00
  174.50
  200.00
   84.75
  288.25
1,568.50
3,732.50
2,539.00
  140.50
6,735.00
2,425.00
1,620.00
  453.75
  468.00

Revenue Labels
ROOM CHARGES             562.00
PHARMACY                 174.50
DRUGS/IV SOLUT           200.00
DRUGS/SELF ADMIN          84.75
PHARMACY/OTHER           288.25
IMPLANTS               1,568.50
MED-SUR SUPPLIES       3,732.50
LABORATORY             2,539.00
XRAY/DIAGNOSTIC          140.50
OPERATING ROOM         6,735.00
ANESTHESIA             2,425.00
RECOVERY ROOM          1,620.00
TREATMENT RM             453.75
OBSERVATION RM           468.00

Request for Question Clarification by mathtalk-ga on 07 May 2004 18:40 PDT
Hi, amazons_truth-ga:

My short program quickly found this solution (amounts are converted to
whole cents, to make the arithmetic exact) and also determined that
there were no additional solutions:

Lo = [17450, 46800, 162000] ;
no

These items' labels are respectively the Pharmacy, the Observation
Room, and the Recovery Room.

Assuming this to be a fairly typical problem, I think the speed will
be satisfactory (it returned in the blink of an eye, running as
interpreted code).

However as it is written in Prolog, and you are intending this for
commercial application, I will raise the issue of how much your budget
will allow to have this integrated with Excel or Access.  To write an
equivalent program in C or Visual Basic will run to dozens of lines;
the Prolog program is essentially four clauses for one predicate
though some additional code would be needed to interface with a VBA
environment like Excel/Access. I intended it to run against input data
in sorted order, but in my experimentation it seemed to work even
without that preparation.

The list price offered for the Question suggests a rather limited
budget, so I thought it best to explore the issue before proposing a
solution that does not meet your requirements.

regards, mathtalk-ga
Answer  
There is no answer at this time.

Comments  
Subject: Re: Pulling a predetermined sum from a list of values
From: drip-ga on 15 Apr 2004 09:08 PDT
 
This sounds very similar to the knapsack problem
(http://www.nist.gov/dads/HTML/knapsackProblem.html), although there
are a few differences, such as that the weights are the same as the
values, and you're looking for an exact sum, not for just the maximal
value. My point, however, is that at first glance this seems to be a
complex algorithmic quandary, and the easiest way to go about it might
just be to do it by brute force. For example, something like the
following might work:

findsum(sum,list[])
  If list is empty, then return true if sum=0, else return false.
  If findsum(sum,list[1..end]) then return true.
  If findsum(sum-list[0],list[1..end]) then return true.
  Otherwise, return false.
end findsum

This particular algorithm would most likely take approximately forever
for a large dataset, but it would be manageable for something small.
There may be ways to speed it up.

At any rate, I doubt that something like this is already coded into
Excel or Access, and you may have to end up writing the code yourself.
Subject: Re: Pulling a predetermined sum from a list of values
From: dwal-ga on 15 Apr 2004 16:22 PDT
 
Using Excel to do this

1) Enter the numbers into column A
2) Enter zero in corresponding cells in column B
3) Set column C equal to the product of A & B, ie set C1 to =A1*B1
4) At the end of column C enter last cell as SUM(C1:C?)

You can manual solve the problem by setting cells in column B to 1 or zero
until the required answer is shown in the SUM cell.

To get excel to solve this you can use the solver function.
Click Tools > Solver

Here set target cell to the SUM cell
equal to <your required value>

By changing cells to B1:B?

Add the following constraints.
B1:B? <= 1
B1:B? >= 0
B1:B? is integer

Hit solve and hey presto.

Seems to work for the simple example you provided, not sure
how it would cope with larger ones.
Subject: Re: Pulling a predetermined sum from a list of values
From: amazons_truth-ga on 16 Apr 2004 06:16 PDT
 
Thank you so much! I'm going to try this in Excel once I get the
solver add-in installed. This is actually for monetary values using 30
at most at a time.
Subject: Re: Pulling a predetermined sum from a list of values
From: mathtalk-ga on 16 Apr 2004 21:09 PDT
 
What should the algorithm do in cases where more than one solution
exists?  I've seen this question asked before in a couple of contexts
in which the intention was to take an accounting shortcut to try and
balance payments and invoices, where invoices may have been paid in
partial payments.

There's in general no guarantee that the solution to finding a subset
of numbers that produces a given sum will be unique (or exist, for
that matter).

-- mathtalk-ga

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy