I have a set of data in a list
eg
john
james
Smith
j
s
from this I need all possible combinations and orders eg
j s James
s j James
smith j james
j james
s j
the list size is not preset and is based off data entered by the user
I have reviewed several solutions on here and have come close to getting what I need for example I get a return of
j s james
s j james
smith j james
but I will never get a result that starts with james
some of the solutions provided in below links Listing all permutations of a string/integer Creating a power set of a Sequence All Possible Combinations of a list of Values
public static IList<IList<T>> PowerSet<T>(IList<T> list)
{
int n = 1 << list.Count;
IList<IList<T>> powerset = new List<IList<T>>();
for (int i = 0; i < n; ++i)
{
IList<T> set = new List<T>();
for (int bits = i, j = 0; bits != 0; bits >>= 1, ++j)
{
if ((bits & 1) != 0)
set.Add(list[j]);
}
powerset.Add(set);
}
return powerset;
}
Throwing a list
at the above code gets the closest i can get but does not return all the possible combinations
I got this code from here but ill be dammed if i can find the original post all credit to original poster not me for above code