コード例 #1
0
        public string GetNormalisedTitle(string title)
        {
            if (title == null)
            {
                return(null);
            }

            title = title.ToLower().Normalize(NormalizationForm.FormKD);

            var actions = new Func <string, string>[]
            {
                this.TrimEpisodeNumberPrefixes,
                this.RemoveModifiersAndDiacritics,
                this.RemoveIgnoredCharacters,
                this.ReplaceSpaceCharacters,
                this.ExpandAmpersands,
                this.RemoveErroneousArticles,
                this.CollapseMultipleSpaces
            };

            title = actions.Aggregate(title, (current, action) => action(current));

            var comparableTitle = title.Trim();

            return(comparableTitle.ToUpperInvariant());
        }
コード例 #2
0
ファイル: TpClassic.cs プロジェクト: thebridge0491/introcs
        public bool FibProp(uint x)
        {
            var funcs = new Func <int, int>[] { Classic.FibLp, Classic.FibI };
            int n     = (int)x % 20 + 1;
            var ans   = Enumerable.Range(0, n).Aggregate((0, 1), (accTup, e) => (accTup.Item1 + accTup.Item2, accTup.Item1)).Item1;

            return(funcs.Aggregate(true, (acc, f) => acc && ans == f(n)));
        }
コード例 #3
0
ファイル: TpClassic.cs プロジェクト: thebridge0491/introcs
        public bool SumToProp(uint x, uint y)
        {
            var funcs = new Func <long, long, long>[] { Classic.SumToLp,
                                                        Classic.SumToI };
            int hi = (int)x % 201 - 50, lo = (int)y % 201 - 50;
            var ans = Enumerable.Range(lo, hi >= lo ? hi + 1 - lo : 0).Select(e =>
                                                                              (long)e).Aggregate(0L, (acc, e) => acc + e);

            return(funcs.Aggregate(true, (acc, f) => acc && ans == f(hi, lo)));
        }
コード例 #4
0
ファイル: TpClassic.cs プロジェクト: thebridge0491/introcs
        public bool SquareProp(uint x)
        {
            var funcs = new Func <float, float>[] { Classic.SquareLp,
                                                    Classic.SquareI };
            float n   = (float)(x % 100 + 1);
            var   ans = Math.Pow(n, 2.0f);

            return(funcs.Aggregate(true, (acc, f) => acc && Util.InEpsilon(ans,
                                                                           f(n), epsilon * ans)));
        }
コード例 #5
0
ファイル: TpClassic.cs プロジェクト: thebridge0491/introcs
        public bool FactProp(uint x)
        {
            var funcs = new Func <long, long>[] { Classic.FactLp, Classic.FactI };
            int n     = (int)x % 19 + 1;
            var ans   = Enumerable.Range(1, n).Select(e =>
                                                      (long)e).Aggregate((acc, e) => acc * e);

            /*bool res = true;
             * foreach (var f in funcs)
             *      res = res && ans == f(n);
             * return res;*/
            return(funcs.Aggregate(true, (acc, f) => acc && ans == f(n)));
        }
コード例 #6
0
ファイル: TpClassic.cs プロジェクト: thebridge0491/introcs
        public bool ExptProp(uint x, uint y)
        {
            var funcs = new Func <float, float, float>[] { Classic.ExptLp,
                                                           Classic.ExptI };
            float b = (float)(x % 19 + 1); float n = (float)(y % 10 + 1);
            var   ans = Math.Pow(b, n);

            /*bool res = true;
             * foreach (var f in funcs)
             *      res = res && Util.InEpsilon(ans, f(b, n), epsilon * ans);
             * return res;*/
            return(funcs.Aggregate(true, (acc, f) => acc && Util.InEpsilon(ans,
                                                                           f(b, n), epsilon * ans)));
        }
コード例 #7
0
        public bool TabulateProp(uint x)
        {
            var funcsL = new Func <Func <int, int>, int, List <int> >[] {
                Seqops.TabulateLp
            };
            var funcsA = new Func <Func <int, int>, int, int[]>[] {
                SeqopsArr.TabulateLp
            };
            int             n    = (int)x % 18 + 1;
            Func <int, int> proc = e => e + 2;
            var             ans  = Enumerable.Range(0, n).Select(e => proc(e));

            return(funcsL.Aggregate(true, (acc, f) => acc &&
                                    ans.SequenceEqual(f(proc, n))) && funcsA.Aggregate(true, (acc, f) => acc &&
                                                                                       ans.SequenceEqual(f(proc, n))));
        }
コード例 #8
0
        public void CallFunctions()
        {
            var funcs = new Func <string, data, string>[] {
                fn1, fn2, fn3
            };

            data d = new data();

            string sz1 = "Start";

            string result = funcs.Aggregate(
                sz1,
                (sz, x) => x(sz, d)
                );

            Console.WriteLine(result);
        }
コード例 #9
0
        public bool IndexFindProp(int el, List <int> xs)
        {
            FSharpFunc <int, bool> predFs = (Converter <int, bool>)(e => el == e);
            var funcsIdxL = new Func <int, List <int>, int>[] { Seqops.IndexOfLp,
                                                                (el1, xs1) => SequenceopsFs.findIndexSeqI(predFs, xs1) };
            var funcsFndL = new Func <int, List <int>, int>[] { Seqops.FindLp };
            var funcsIdxA = new Func <int, int[], int>[] { SeqopsArr.IndexOfLp };
            var funcsFndA = new Func <int, int[], int>[] { SeqopsArr.FindLp };
            var ansIdx    = xs.IndexOf(el);
            var ansFnd    = xs.Find(e => el == e);

            return(funcsIdxL.Aggregate(true, (acc, f) => acc &&
                                       ansIdx == f(el, xs)) && funcsFndL.Aggregate(true, (acc, f) =>
                                                                                   acc && ansFnd == f(el, xs)) && funcsIdxA.Aggregate(true, (acc, f) => acc &&
                                                                                                                                      ansIdx == f(el, xs.ToArray())) && funcsFndA.Aggregate(true, (acc, f) =>
                                                                                                                                                                                            acc && ansFnd == f(el, xs.ToArray())));
        }
コード例 #10
0
        static Parser <ESExpression> BeginExpressionFactory()
        {
            Func <Parser <ESExpression>, Parser <ESExpression> >[] functions =
                new Func <Parser <ESExpression>, Parser <ESExpression> >[] {
                SubExpression,
                Casts,
                PowerRoot,
                MultiplyDivideModulo,
                AddSubtract,
                Comparisons,
                Conditionals,
                AssignMove
            };

            Parser <ESExpression> accumulated = functions.Aggregate((Parser <ESExpression>)null, (prev, next) => next(prev));

            return(accumulated);
        }
コード例 #11
0
ファイル: Config.cs プロジェクト: crapitan/Fiffi
 public Configuration <T> Commands(params Func <ICommand, Task>[] f)
 => this.Tap(x => x.dispatch = f.Aggregate((l, r) => async c =>
 {
     await l(c);
     await r(c);
 }));