Skip to content

Instantly share code, notes, and snippets.

@sholev
Last active June 7, 2016 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sholev/04e221f2aaf02c00962dbe7d444a1674 to your computer and use it in GitHub Desktop.
Save sholev/04e221f2aaf02c00962dbe7d444a1674 to your computer and use it in GitHub Desktop.
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 = predicates.All(predicate => predicate(i));
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