Advertisement
Guest User

Untitled

a guest
Dec 20th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.37 KB | None | 0 0
  1. var foo = new int[]{1,1,4,5,6,2,3,3,1,7,2,4,2,3};
  2. foo
  3.     .Aggregate(new List<List<int>>(), (seed, next) => {
  4.         var listToAddTo = seed.FirstOrDefault(l=> !l.Contains(next));
  5.         if (listToAddTo == null)
  6.         {
  7.             seed.Add(new List<int>(){ next });
  8.         }
  9.         else {
  10.             listToAddTo.Add(next);
  11.         }
  12.        
  13.         return seed;
  14.     })
  15.     .Select(x => x.OrderBy(y => y))
  16.     .SelectMany(x => x);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement