Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. - "1->2"
  2. - "1->2->3"
  3. - "1->2->3->4"
  4. - "5->6"
  5. - "5->6->7"
  6. - "5->6->7->8"
  7.  
  8. "1->2->3->4"
  9. "5->6->7->8"
  10.  
  11. public class Program
  12. {
  13. public static void Main(string[] args)
  14. {
  15. List<(string, i)> flattenedPaths = new List<(string, i)>
  16. {
  17. ("1->2", 0)
  18. ("1->2->3", 1)
  19. ("1->2->3->4", 2)
  20. ("5->6", 3)
  21. ("5->6->7", 4)
  22. ("5->6->7->8", 5)
  23. };
  24.  
  25. IEnumerable<string> uniquePaths = GetUniquePaths(flattenedPaths);
  26. }
  27.  
  28. public static IEnumerable<(string, int)> GetUniquePaths(List<(string, int)> Paths)
  29. {
  30. for (int i = 0; i < Paths.Count; i++)
  31. {
  32. bool doesMatchContain = Paths.Skip(i)
  33. .Any(x => x.Item1.Contains(Paths[i].Item1));
  34.  
  35. if (!doesMatchContain)
  36. yield return Paths[i];
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement