Last active
June 7, 2016 20:31
-
-
Save sholev/04e221f2aaf02c00962dbe7d444a1674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace FunctionalProgramming | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
class ListOfPredicates | |
{ | |
static void Main(string[] args) | |
{ | |
var ceiling = int.Parse(Console.ReadLine()); | |
var divisors = | |
Console.ReadLine() | |
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) | |
.Select(int.Parse); | |
var predicates = divisors.Select(divisor => (Func<int, bool>)(n => n % divisor == 0)).ToArray(); | |
var result = new List<int>(); | |
for (int i = 1; i <= ceiling; i++) | |
{ | |
bool dreddApproved = true; | |
foreach (Func<int, bool> predicate in predicates) | |
{ | |
if (!predicate(i)) | |
{ | |
dreddApproved = false; | |
break; | |
} | |
} | |
if (dreddApproved) | |
{ | |
result.Add(i); | |
} | |
} | |
Console.WriteLine(string.Join(" ", result)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment