Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static IEnumerable<IEnumerable<T>> GetPermutations<T>(IReadOnlyCollection<T> list, int length)
- {
- if (length == 1) return list.Select(t => new[] { t });
- return GetPermutations(list, length - 1)
- .SelectMany(t => list.Where(e => !t.Contains(e)),
- (t1, t2) => t1.Concat(new[] { t2 }));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement