Advertisement
GabrielDas

Untitled

Jun 4th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P09ListOfPredicates
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int upperBound = int.Parse(Console.ReadLine());
  12. var numbers = Enumerable.Range(1, upperBound).ToList();
  13.  
  14.  
  15. int[] dividers = Console.ReadLine()
  16. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  17. .Select(int.Parse)
  18. .Distinct()
  19. .ToArray();
  20.  
  21. List<Predicate<int>> predicates = new List<Predicate<int>>();
  22.  
  23. foreach (var currentNumber in dividers)
  24. {
  25. predicates.Add(x => x % currentNumber == 0);
  26. }
  27.  
  28. for (int i = 0; i < numbers.Count; i++)
  29. {
  30. for (int j = 0; j < predicates.Count; j++)
  31. {
  32. if (!predicates[j](numbers[i]))
  33. {
  34. numbers.Remove(numbers[i]);
  35. i--;
  36. break;
  37. }
  38.  
  39. }
  40.  
  41. }
  42.  
  43. Console.WriteLine(String.Join(" ", numbers));
  44.  
  45. }
  46.  
  47.  
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement