예제 #1
0
 public static bool history_contains(List <List <PerformanceStats> > aHistory, CharacterIndex[] aChars)
 {
     bool[] r = new bool[aChars.Count()];
     foreach (var e in aHistory)
     {
         foreach (var f in e)
         {
             for (int i = 0; i < aChars.Count(); i++)
             {
                 if (aChars[i] == f.Character)
                 {
                     r[i] = true;
                 }
             }
         }
     }
     return(r.Aggregate((e, f) => e & f));
 }
예제 #2
0
        public static void Test1()
        {
            IEnumerable <int> xs = Enumerable.Range(1, 10);

            //fold
            int a = xs.Aggregate((acc, x) => acc + x);

            //foldBack
            int b = xs.Reverse().Aggregate((acc, x) => acc + x);

            IEnumerable <bool> ys = new bool[] { true, false, true, false };

            bool c = ys.Aggregate((acc, y) => acc && y); //non-short-circuit
            bool d = ys.And();

            Console.WriteLine(a);
            Console.WriteLine(b);
            Console.WriteLine(c);
            Console.WriteLine(d);
        }
예제 #3
0
        private bool IsPandigitalProduct(int n1, int n2)
        {
            bool[] digits  = new bool[9];
            int    product = n1 * n2;
            string result  = n1.ToString() + n2.ToString() + product.ToString();

            if (result.Length != 9)
            {
                return(false);
            }

            for (int i = 0; i < result.Length; ++i)
            {
                int value = int.Parse(result[i].ToString());
                if (value == 0 || digits[value - 1] == true)
                {
                    return(false);
                }

                digits[value - 1] = true;
            }
            return(digits.Aggregate((a, b) => a && b));
        }
예제 #4
0
    public override IEnumerator <bool> EvaluateInput()
    {
        IEnumerator <bool>[] inputEvaluation = actionFragments.Select(af => af.EvaluateInput()).ToArray();
        bool[] results    = new bool[inputEvaluation.Length];
        bool[] hasResults = new bool[inputEvaluation.Length];

evaluate:
        for (int i = 0; i < inputEvaluation.Length; i++)
        {
            hasResults[i] = inputEvaluation[i].MoveNext();
            if (hasResults[i])
            {
                results[i] = inputEvaluation[i].Current;
            }
        }

        if (hasResults.All(h => !h) && !AnyOfThem)
        {
            yield return(results.Aggregate(false, (a, b) => a & b));
        }
        else if (hasResults.Any(h => !h) && results.Any(h => h) && AnyOfThem)
        {
            yield return(true);
        }
        else if (hasResults.All(h => !h) && results.All(h => !h))
        {
            yield return(false);

            yield break;
        }
        else
        {
            yield return(false);

            goto evaluate;
        }
    }