SHARE
TWEET

List of Predicates

a guest Jul 16th, 2016 168 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top