number anagram
This is actually quite a difficult problem to solve. As a example,
suppose you had the following numbers in column A:
15
12
10
9
7
4
3
and the value in B was 28. You could choose a "Largest Fit" algorithm,
i.e. choose the largest available number which could be included in the
sum.
In this instance your first choice would be 15, then 12 but then you
find there isn't a 1, so you would discard the 12 and choose 10 and
then you find that 3 fitted the bill, so the answer is 15, 10 and 3.
However, another solution could be 12, 9, 4 and 3, and with a larger
range of numbers there could be many possible solutions.
Suppose, now, the number in B was 26. Again you would choose 15 first,
then 12, and then discard this, choose 10 and then discard this, choose
9 and then discard this, choose 7 then choose 4 to arrive at the
solution. Another solution would be 12, 7, 4 and 3.
The largest fit algorithm would generally find the solution with the
fewest number of additions, but the numbers in A have to be taken in
decreasing order of magnitude for this method to work, and it is
recursive in nature.
Perhaps someone might be encouraged to code the method in VBA for you
....
Hope this helps.
Pete
|