Advertisement
Guest User

List of Predicates

a guest
Jul 16th, 2016
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ListOfPredicates
  6. {
  7.     class ListOfPredicates
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int range = int.Parse(Console.ReadLine());
  12.             int[] toDivide = Console.ReadLine().Split(' ').Select(int.Parse).Distinct().ToArray();
  13.  
  14.             Func<int, bool>[] predicates = toDivide.Select(div => (Func<int, bool>)(n => n % div == 0)).ToArray();
  15.  
  16.             for (int j = 1; j <= range; j++)
  17.             {
  18.                 bool isDivisable = true;
  19.  
  20.                 foreach (var predicate in predicates)
  21.                 {
  22.                     if (!predicate(j))
  23.                     {
  24.                         isDivisable = false;
  25.                         break;
  26.                     }
  27.                 }
  28.  
  29.                 if (isDivisable)
  30.                 {
  31.                     Console.Write("{0} ", j);
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement