Advertisement
LaughingMan

String Permutations

Jul 19th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.36 KB | None | 0 0
  1. public static IEnumerable<IEnumerable<T>> GetPermutations<T>(IReadOnlyCollection<T> list, int length)
  2.         {
  3.             if (length == 1) return list.Select(t => new[] { t });
  4.  
  5.             return GetPermutations(list, length - 1)
  6.                 .SelectMany(t => list.Where(e => !t.Contains(e)),
  7.                     (t1, t2) => t1.Concat(new[] { t2 }));
  8.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement