Hi,
I need to generate combinations from a list of entries. For example, I may have n entries and I want to generate combinations of k (<=n) of those entries.
Example 1:
Entries: a,b //n=2
k = 1
Output: a,b
Example 2:
Entries: a,b //n=2
k = 2
Output: aa,ab,ba,bb
Example 3:
Entries: a,b,c //n=3
k = 1
Output: a,b,c
Example 4:
Entries: a,b,c //n=3
k = 2
Output: aa,ab,ac,ba,bb,bc,ca,cb,cc
Example 5:
Entries: a,b,c //n=3
k = 3
Output: aaa,aab,aac,aba,abb,abc,aca,acb,acc,baa,bab,bac,bba,bbb,bbc,bca,bcb,bcc,caa,cab,cac,cba,cbb,cbc,cca,ccb,ccc
Entries and k are variable.
I found a number of combination related samples on the web but mostly they are overly complicated and do not cover this specific case I am trying to do.
Any ideas how to do what I am trying to do? If you have a sample code to share, it would be great, otherwise, a possible algorithm or a link to another source that does this are also highly appreciated.