Combination Algorithm

  • Thread starter Thread starter resueman
  • Start date Start date
R

resueman

Can somebody help me with this problem:
I have an array of string

dim nSet as Variant
nSet = Array("A", "B", "C", "D")

I want the function to return all the possible
combinations (n items choose k). Then function, getComb
should return:

("AB","AC","AD","BC","BC","CD") when I use getComb(2, nSet)

And

("ABC","ABD","ACD","BCD") when I use getComb(3,nSet)

And

("ABCD") when I use getComb(4,nSet)

Any help is appreciated!
 
Hi,

If the values are one character long, in a table, one per record, single
field called f1, no duplicated values, then


SELECT a.f1 & b.f1 & c.f1 & d.f1 As AllMonotoneCombi
FROM ((( MyTable As a LEFT JOIN MyTable As b ON a.f1 >b.f1)
LEFT JOIN myTable As c ON b.f1>c.f1)
LEFT JOIN myTable As d ON c.f1>d.f1


If the values are possibly more than one character long, and we can use a
coma to delimit them:

SELECT a.f1 & ", " & b.f1 & ", " & c.f1 & ", " & d.f1 As AllMonotoneCombi
FROM ...



Hoping it may help,
Vanderghast, Access MVP
 
Back
Top