I have this method:
static List<string> permutation(List<string> lst)
{
switch (lst.Count)
{
case 0:
case 1:
return lst;
default:
List<string> l = new List<string>();
for (int i = 0; i < lst.Count; i++)
{
string m = lst[i];
List<string> remLst = lst.Except(new List<string> { m }).ToList();
List<string> tmp = permutation(remLst);
for (int i2 = 0; i2 < tmp.Count; i2++)
{
l.Add(m + tmp[i2]);
}
}
return l;
}
}
which gives all permutations of the list lst
.
The idea is to one by one extract all elements, place them at first position and recur for remaining list. Python equivalent here.
How to convert it from recursive to tail-recursive?