i am using the following C# function to get a powerset limited to subsets of a minimal length
string[] PowerSet(int min_len, string set)
{
IEnumerable<IEnumerable<string>> seed =
new List<IEnumerable<string>>() { Enumerable.Empty<string>() };
return set.Replace(" ", "")
.Split(',')
.Aggregate(seed, (a, b) => a.Concat(a.Select(x => x.Concat(new[] { b }))))
.Where(subset => subset.Count() >= min_len)
.Select(subset => string.Join(",", subset))
.ToArray();
}
the problem is that when the original set is large, the algorithm has to work very hard even if the minimal length is large as well.
e.g:
PowerSet(27, "1,11,12,17,22,127,128,135,240,254,277,284,292,296,399,309,322,326,333,439,440,442,447,567,580,590,692,697");
should be very easy, but is too lengthily for the above function. i am looking for a concise modification of my function which could efficiently handle these cases.