View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.newusers
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default Looping through permutations

wrote:
This was very helpful......
After putting the variables into watch mode, I think
that I get a better sense of how/why this works the
way it does.


My apologies for not explaining the algorithm. I thought it might be a
homework assignment, and some things should be left for the student to
figure out ;-).

The key trick is how we choose the "next combination index". To understand
that code, it might be helpful to review how we generate all combinations
efficiently.

In general, if we want to generate all combinations selecting k objects from
n objects, we might write the following k nested for-loops:

for idx(1) = 1 to n-(k-1)
for idx(2) = idx(1)+1 to n-(k-2)
[....]
for idx(k-1) = idx(k-2)+1 to n-1
for idx(k) = idx(k-1)+1 to n
combo = array(myData(idx(1)),myData(idx(2)),...,myData(idx (k)))
next idx(k),...,idx(1)

The "next combination index" implements that logic effectively for a
variable number of for-loops.

Marston wrote:
Now the problem I'm facing is that there is
some kind of mismatch - on the linest with
the xrng.


I will comment on that in the thread that you posted separately titled
"Runtime error on linest".