Permutations: Difference between revisions

m
Oops. Previous change didn't fully work. Need "where T : IComparable<T>", not "where T : class"
(1) Needs to be in special class for extensions. 2) T needs to be scoped to class.)
m (Oops. Previous change didn't fully work. Need "where T : IComparable<T>", not "where T : class")
Line 2,026:
<lang csharp>public static class Extension
{
public static IEnumerable<IEnumerable<T>> Permutations<T>(this IEnumerable<T> values) where T : classIComparable<T>
{
if (values.Count() == 1)
return new[] { values };
return values.SelectMany(v => Permutations(values.Where(x => x.CompareTo(v) != v0)), (v, p) => p.Prepend(v));
}
}</lang>
Anonymous user