コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("=== Etap 1 ===\n");

            IEnumerable naturals = new Naturalne(1);

            Console.WriteLine("Liczby naturalne");
            PrintIEnumerable(naturals, 10);

            IEnumerable random = new Losowe(667, 1000);

            Console.WriteLine("Liczby losowe");
            PrintIEnumerable(random, 10);

            IEnumerable tetranacci = new Tetranacci();

            Console.WriteLine("Liczby Tetranacciego");
            PrintIEnumerable(tetranacci, 10);

            IEnumerable catalan = new Catalan();

            Console.WriteLine("Liczby Catalana");
            PrintIEnumerable(catalan, 10);

            int[]       arr1       = { 56, 6, -9, 1 };
            IEnumerable polynomial = new Wielomian(arr1);

            Console.WriteLine("Wartosci wielomianu");
            PrintIEnumerable(polynomial, 10);

            Console.WriteLine("=== Etap 2 ===\n");

            IModifier first5 = new PoczatkoweN(5);

            Console.WriteLine(first5.Name);
            PrintIEnumerable(first5.Modify(random));

            IModifier linear = new TransformacjaLiniowa(10, 5);

            Console.WriteLine(linear.Name);
            PrintIEnumerable(linear.Modify(naturals), 10);

            int[]     arr2   = { 3, 5, 4, 4, 4, 1, 1, 2, 3, 5, 3, 4, 2, 2, 2 };
            IModifier unique = new TylkoRozne();

            Console.WriteLine(unique.Name);
            PrintIEnumerable(unique.Modify(arr2));

            IModifier prime = new LiczbyPierwsze();

            Console.WriteLine(prime.Name);
            PrintIEnumerable(prime.Modify(naturals), 10);

            Console.WriteLine("=== Etap 3 ===\n");

            IModifier localMin = new MinimaLokalne();

            Console.WriteLine(localMin.Name);
            PrintIEnumerable(localMin.Modify(new int[0]));
            PrintIEnumerable(localMin.Modify(new int[] { 3 }));
            PrintIEnumerable(localMin.Modify(new int[] { 4, 1 }));
            PrintIEnumerable(localMin.Modify(new int[] { 2, 5 }));
            PrintIEnumerable(localMin.Modify(arr2));

            Console.WriteLine("=== Etap 4 ===\n");

            IMerger multiply = new Mnoz();

            Console.WriteLine(multiply.Name);
            PrintIEnumerable(multiply.Merge(naturals, prime.Modify(naturals)), 10);

            Console.WriteLine("=== Etap 5 ===\n");

            //naturals = new Naturalne();
            //IModifier[] modifiers = {first5, linear, prime};
            //IModifier composed = new ModyfikatorZlozony(modifiers);
            //Console.WriteLine(composed.Name);
            //PrintIEnumerable(composed.Modify(naturals),10);

            //IModifier[] modifiers2 = {first5, prime, linear};
            //IModifier composed2 = new ModyfikatorZlozony(modifiers2);
            //Console.WriteLine(composed2.Name);
            //PrintIEnumerable(composed2.Modify(naturals),10);

            //TabliczkaDodawania table = new TabliczkaDodawania();
            //Console.WriteLine("Tabliczka Dodawania\n");
            //foreach ( IEnumerable seq in table )
            //    PrintIEnumerable(seq);
        }
コード例 #2
0
ファイル: Modyfikatory.cs プロジェクト: PatrykCzapla/C_Sharp
        public IEnumerable Modify(IEnumerable sequence)
        {
            IModifier unique = new TylkoRozne();
            var       a = unique.Modify(sequence);
            int       ile = 0;
            int       i = 0;
            int       prev1 = int.MaxValue, prev2 = int.MaxValue;

            foreach (var elem in a)
            {
                ile++;
            }


            foreach (var elem in a)
            {
                if (ile == 1)
                {
                    yield return(elem);

                    continue;
                }
                if (ile == 2)
                {
                    if (i == 0)
                    {
                        prev1 = (int)elem;
                        i++;
                        continue;
                    }
                    if (i == 1)
                    {
                        i++;
                        yield return(prev1 < (int)elem ? prev1 : elem);

                        continue;
                    }
                }
                if (i == 0)
                {
                    prev1 = (int)elem;
                    i++;
                    continue;
                }
                if (i == 1)
                {
                    prev2 = (int)elem;
                    yield return(prev1 < (int)elem ? prev1 : elem);

                    i++;
                    continue;
                }
                if (i == (ile - 1))
                {
                    if ((int)elem < prev2)
                    {
                        i++;
                        yield return(elem);

                        continue;
                    }
                }
                if (IsMin(prev1, prev2, (int)elem))
                {
                    i++;
                    yield return(prev2);
                }
                prev1 = prev2;
                prev2 = (int)elem;
            }
        }