Advertisement
nassss

Untitled

Mar 11th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace DNA
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. var dna = "TTTAAAAAGGTTTAAAAAGGAAAACCCCCCAAAAACCCCCAAAAACCCCCCAAAAAGGGTTTAAAAGAAAACCCCCAGGGTTTAGGGTTTAAAAAAGGGTTTA";
  12. var duplicateSequences = Analyze(dna);
  13. foreach (var item in duplicateSequences)
  14. {
  15. Console.WriteLine(item);
  16. }
  17. }
  18.  
  19. public static IEnumerable<string> Analyze(string dna)
  20. {
  21. var workCollection = new HashSet<string>();
  22. var outputCollection = new HashSet<string>();
  23.  
  24. for (int i = 0; i < dna.Length; i++)
  25. {
  26. if (dna.Length - i < 10)
  27. {
  28. break;
  29. }
  30. var temp = string.Empty;
  31. for (int j = i; j < i + 10; j++)
  32. {
  33. temp += dna[j];
  34. }
  35. if(workCollection.Add(temp))
  36. {
  37. continue;
  38. }
  39. else
  40. {
  41. outputCollection.Add(temp);
  42. }
  43.  
  44. }
  45. return outputCollection;
  46. }
  47.  
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement