public static class Extension { public static IEnumerable> Permutations(this IEnumerable values) where T : IComparable { if (values.Count() == 1) return new[] { values }; return values.SelectMany(v => Permutations(values.Where(x => x.CompareTo(v) != 0)), (v, p) => p.Prepend(v)); } }