View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Sam Wilson Sam Wilson is offline
external usenet poster
 
Posts: 523
Default Isolate UNIQUE combination of Z cells from a range N that adds up

It depends entirely on N and Z - there are N!/(Z!(N-Z)!) combinations which
for large N can quickly become problematic.

If Z is reasonably low you can nest loops - say Z=3

for i = 3 to N
for j = 2 to i
for k = 1 to j
'pick element i of N
'pick element j of N
'pick element k of N
'add these elements, see if it's right
next k
next j
next i

If you want Z to be variable, then you'll need to construct an array of size
Z with elements consisting of 1 or 0, and then switch these 1s and 0s off in
Binary sequence to find your target - but you could be talking days of
computation as there are 2^Z combinations.

"alex" wrote:

I have a range of N cells, all in one column and all unique numbers. I also
know that Z cells from this range adds up to a number R. This combination of
Z cells is unique, i.e. there is only one combination of Z cells that adds up
to R.

How can I have these Z cells shown in a separate column? In other words,
how can I isolate them?

Thanks for any help!!!