Skip to content

Instantly share code, notes, and snippets.

@mteper
Last active October 20, 2015 21:43
Show Gist options
  • Save mteper/b329986049eae046a80f to your computer and use it in GitHub Desktop.
Save mteper/b329986049eae046a80f to your computer and use it in GitHub Desktop.
// response to http://blog.thesoftwarementor.com/2015/10/20/using-f-to-solve-a-constraints-problem/
public static void Main(string[] args)
{
var numbers = Enumerable.Range(0, 10000);
var modFactor = 3;
var constraints = new Func<int, bool>[]
{
i => i.ToString().Length == 4,
i => i % modFactor == 0,
i => i > 10 && i.ToString().First() == i.ToString().Last()
};
Func<int, bool> isMatch = i => constraints.All(c => c(i));
foreach (var item in numbers.Where(isMatch))
{
Console.WriteLine(item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment