using System; using System.Collections.Generic; using System.Linq; static class Program { private static void Main(string[] args) { "foo".ToCharArray().Permutate().ForEach(Console.WriteLine); "abbccc".ToCharArray().Permutate().ForEach(Console.WriteLine); Console.Read(); } public static List Permutate(this IEnumerable s) { return s.SelectMany(x => { var index = Array.IndexOf(s.ToArray(), x); return s.Where((y, i) => i != index) .Permutate() .Select(y => new string(new[] {x}.Concat(y).ToArray())) .Union(new[] {new string(new[] {x})}); }).Distinct().Where(x => x.Length == s.Count()).ToList(); } }