예제 #1
0
        public static void DivisionTest()
        {
            Console.WriteLine("########## PART 3 ############");
            var coeffientsOne   = new int[] { 1, 1, 0, 1 };
            var polyOne         = new Polynomial(coeffientsOne);
            var coeffientsTwo   = new int[] { 1, 1 };
            var polyTwo         = new Polynomial(coeffientsTwo);
            var coeffientsThree = new int[] { 1, 1, 0, 0, 0, 1 };
            var polyThree       = new Polynomial(coeffientsThree);
            var coeffientsFour  = new int[] { 1, 1, 1 };
            var polyFour        = new Polynomial(coeffientsFour);
            var coeffientsFive  = new int[] { 1, 1, 1, 0, 0, 1, 0, 1 };
            var polyFive        = new Polynomial(coeffientsFive);
            var coeffientsSix   = new int[] { 1, 0, 1, 0, 1 };
            var polySix         = new Polynomial(coeffientsSix);

            var divisionResultOne = polyOne.Divide(polyTwo);
            var remainderOne      = divisionResultOne[1].GreatestPower() >= 0 ? divisionResultOne[1].ToString() : "0";

            Console.WriteLine("(" + polyOne.ToString() + ") / (" + polyTwo.ToString() + ") = " + divisionResultOne[0].ToString() + " Remainder: " + remainderOne);
            Console.WriteLine("(" + polyTwo.ToString() + ") * (" + divisionResultOne[0] + ") + " + divisionResultOne[1] + " = " + polyTwo.Product(divisionResultOne[0]).Sum(divisionResultOne[1]));
            var divisionResultTwo = polyThree.Divide(polyFour);
            var remainderTwo      = divisionResultTwo[1].GreatestPower() >= 0 ? divisionResultTwo[1].ToString() : "0";

            Console.WriteLine("(" + polyThree.ToString() + ") / (" + polyFour.ToString() + ") = " + divisionResultTwo[0].ToString() + " Remainder: " + remainderTwo);
            Console.WriteLine("(" + polyFour.ToString() + ") * (" + divisionResultTwo[0] + ") + " + divisionResultTwo[1] + " = " + polyFour.Product(divisionResultTwo[0]).Sum(divisionResultTwo[1]));
            var divisionResultThree = polyFive.Divide(polySix);
            var remainderThree      = divisionResultThree[1].GreatestPower() >= 0 ? divisionResultThree[1].ToString() : "0";

            Console.WriteLine("(" + polyFive.ToString() + ") / (" + polySix.ToString() + ") = " + divisionResultThree[0].ToString() + " Remainder: " + remainderThree);
            Console.WriteLine("(" + polySix.ToString() + ") * (" + divisionResultThree[0] + ") + " + divisionResultThree[1] + " = " + polySix.Product(divisionResultThree[0]).Sum(divisionResultThree[1]));
            Console.WriteLine();
        }