public void Apply_Eight() { Func <int, int, int, int, int, int, int, int, int> factorial = YCombinator.Apply <int, int, int, int, int, int, int, int, int>(func => (a, b, c, d, e, f, g, h) => a == 0 ? 1 : a * func(a - b - c - d - e - f - g - h, b, c, d, e, f, g, h)); int value = -1; value = factorial(10, 1, 0, 0, 0, 0, 0, 0); Assert.AreEqual(3628800, value); value = factorial(10, 0, 1, 0, 0, 0, 0, 0); Assert.AreEqual(3628800, value); value = factorial(10, 0, 0, 1, 0, 0, 0, 0); Assert.AreEqual(3628800, value); value = factorial(10, 0, 0, 0, 1, 0, 0, 0); Assert.AreEqual(3628800, value); value = factorial(10, 0, 0, 0, 0, 1, 0, 0); Assert.AreEqual(3628800, value); value = factorial(10, 0, 0, 0, 0, 0, 1, 0); Assert.AreEqual(3628800, value); value = factorial(10, 0, 0, 0, 0, 0, 0, 1); Assert.AreEqual(3628800, value); }
public void Apply_One() { Func <int, int> factorial = YCombinator.Apply <int, int>(f => n => n == 0 ? 1 : n * f(n - 1)); int value = factorial(10); Assert.AreEqual(3628800, value); }
static void Main() { var fac = YCombinator <int, int> .Fix(f => x => x < 2? 1 : x *f(x - 1)); var fib = YCombinator <int, int> .Fix(f => x => x < 2?x : f(x - 1) + f(x - 2)); Console.WriteLine(fac(10)); Console.WriteLine(fib(10)); }
public void Apply_Two() { Func <int, int, int> factorial = YCombinator.Apply <int, int, int>(func => (a, b) => a == 0 ? 1 : a * func(a - b, b)); int value = -1; value = factorial(10, 1); Assert.AreEqual(3628800, value); }
public void Apply_Four() { Func <int, int, int, int, int> factorial = YCombinator.Apply <int, int, int, int, int>(func => (a, b, c, d) => a == 0 ? 1 : a * func(a - b - c - d, b, c, d)); int value = -1; value = factorial(10, 1, 0, 0); Assert.AreEqual(3628800, value); value = factorial(10, 0, 1, 0); Assert.AreEqual(3628800, value); value = factorial(10, 0, 0, 1); Assert.AreEqual(3628800, value); }
internal bool CanInline() { var nodes = Block.Nodes; var isInline = YCombinator.Y <Node, bool>(self => node => { var block = node as Block; if (block != null) { return(block.Nodes.All(self)); } var text = node as Text; var tag = node as Tag; return(text != null || (tag != null && tag.IsInline)); }); // Empty tag if (!nodes.Any()) { return(true); } // Text-only or inline-only tag if (1 == nodes.Count) { return(isInline(nodes.First())); } // Multi-line inline-only tag if (Block.Nodes.All(isInline)) { for (int i = 1, len = nodes.Count; i < len; ++i) { if (nodes[i - 1] as Text != null && nodes[i] as Text != null) { return(false); } } return(true); } // Mixed tag return(false); }
public static NumeralWrapper Factorial(this NumeralWrapper numeral) => YCombinator <NumeralWrapper, NumeralWrapper> .Y(Factorial)(numeral);