How to .....

  • Thread starter Thread starter S S S S S
  • Start date Start date
S

S S S S S

I've a set of numbers and want to find which two numbers in the set can be
added up to a specified number. For example, the data set is {2,4,5,6,9,13}
and I want to know which two numbers will be added up to 8. The system
should tell me they are 2 and 6. Thanks!

SL
 
One way but you need the solver add-in installed (it comes with
excel/office,check under tools>add-ins)
put the data set in let's say A2:A8, in B2:B8 put a set of ones {1,1,1 etc}
in the adjacent cells
in C2 put 8, in D2 put

=SUMPRODUCT(A2:A7,B2:B7)

select D2 and do tools>solver, set target cell $D$2 (should come up
automatically if selected)

Equal to a Value of 8, by changing cells $B$2:$B$7, click add under Subject
to the constraints of:
in Cell reference put

$B$2:$B$7

from dropdown select Bin, click OK and click Solve, Keep solver solution
and look at the table

2 1
4 0
5 0
6 1
9 0
13 0


there you can see that 4 ones have been replaced by zeros and the adjacent
cells to the 2 ones
total 8
 
Back
Top