コード例 #1
0
 public static Int64 Factorial(this Int64 source)
 {
     if (source == 0)
     {
         return(1);
     }
     return(FiniteIntList.GetItems(1, source).Aggregate((result, item) => result *= item));
 }
コード例 #2
0
 public static Object Solve()
 {
     return(FiniteIntList.GetItems(Money, 0, 200).SelectMany(
                a => FiniteIntList.GetItems(a, 0, 100).SelectMany(
                    b => FiniteIntList.GetItems(b, 0, 50).SelectMany(
                        c => FiniteIntList.GetItems(c, 0, 20).SelectMany(
                            d => FiniteIntList.GetItems(d, 0, 10).SelectMany(
                                e => FiniteIntList.GetItems(e, 0, 5).SelectMany(
                                    f => FiniteIntList.GetItems(f, 0, 2).Select(
                                        counter => 1))))))).Count());
 }
コード例 #3
0
 public static Object Solve()
 {
     return(FiniteIntList.GetItems(2, 9).SelectMany(d => FiniteIntList.GetItems(d - 1, 1).Select(n => new Fraction(n, d))) // Generates a list of all possible lowest term fractions (4/8)
            .Select(f => new                                                                                               // Expands all lowest term fractions to include all possible higher term fractions (49/98)
     {
         f,
         fl = FiniteIntList.GetItems(1, 9).Select(p => new Fraction(f.n + p * 10, f.d + p * 10)).Concat(
             FiniteIntList.GetItems(1, 9).Select(p => new Fraction(f.n + p * 10, f.d * 10 + p))).Concat(
             FiniteIntList.GetItems(1, 9).Select(p => new Fraction(f.n * 10 + p, f.d + p * 10))).Concat(
             FiniteIntList.GetItems(1, 9).Select(p => new Fraction(f.n * 10 + p, f.d * 10 + p)))
              .Where(l => l.n < l.d)
     })
            .SelectMany(o => o.fl.Where(fl => fl == o.f))                                                                              // Select all higher term fractions that equal their lower term fraction
            .Multiply()
            .Normalize()
            .Denominator);
 }