public void Test_Product_multiplier(int initValue, int multiplier, int expectedResult)
        {
            var digitsList = DigitsList.ConvertToDigitListe(initValue);
            var resultList = DigitsList.Product(digitsList, multiplier);
            var result     = DigitsList.ConvertToNumber(resultList);

            Assert.Equal(expectedResult, result);
        }
Beispiel #2
0
        public static BigFraction AddFraction(BigFraction a, BigFraction b)
        {
            List <int> t1  = DigitsList.Product(a.Numerator, b.Denominator);
            List <int> t2  = DigitsList.Product(b.Numerator, a.Denominator);
            var        num = DigitsList.Sum(t1, t2);
            var        dem = DigitsList.Product(a.Denominator, b.Denominator);

            return(new BigFraction {
                Numerator = num, Denominator = dem
            });
        }
Beispiel #3
0
        public int GetFactorialdigitsum(int factorial)
        {
            List <int> digits = new List <int>()
            {
                1
            };

            for (int i = 1; i <= factorial; i++)
            {
                digits = DigitsList.Product(digits, multiplier: i);
            }

            return(digits.Sum(e => e));
        }
        public long GetSumOfDigits(int exponent)
        {
            List <int> digits = new List <int>()
            {
                1
            };

            for (int i = 0; i < exponent; i++)
            {
                digits = DigitsList.Product(digits, multiplier: 2);
            }

            var sumOfDigit = digits.Sum(e => e);

            return(sumOfDigit);
        }
        public bool NumeratorHasMoreDigitsThanDenominator(int iterationNumber)
        {
            /*
             *   1 + 1/(2 + 1/2..)
             *   1+ 1/seriesum
             *
             * seriesum=t/n
             * seriesum=2 +1/seriesum = 2+1/(t/n)=2+n/t=(2*t+n)/t
             *
             */

            List <int> teller = new List <int> {
                2
            };
            List <int> nevner = new List <int> {
                1
            };

            //seriesum=t/n = 2

            while (iterationNumber > 1)
            {
                // (2*t+n)/t

                //2*t
                //       List<int> a = DigitsList.Product(teller, 2);

                //2*t+n
                var tmp2 = DigitsList.Sum(DigitsList.Product(teller, 2), nevner);
                // /t
                nevner = teller;
                teller = tmp2;

                iterationNumber--;
            }

            //1 + 1 / seriesum
            // 1 +1/(t/n) = (n+t)/t
            var tmp = teller;

            teller = DigitsList.Sum(nevner, teller);
            nevner = tmp;

            //finn all siffer i teller og nevner
            return(teller.Count > nevner.Count);
        }
Beispiel #6
0
        public long GetLastTenDigits(int topower)
        {
            List <int> digitlist = new List <int>();

            for (int i = 1; i <= topower; i++)
            {
                List <int> liste = DigitsList.ConvertToDigitListe(i);

                for (int j = 2; j <= i; j++)
                {
                    liste = DigitsList.Product(liste, MaxDigits, i);
                }

                digitlist = DigitsList.Sum(digitlist, liste);
            }

            return(DigitsList.ConvertToNumberLong(digitlist.Take(MaxDigits).ToList()));
        }
        public long GetMaximumDigitalSum(int abelow, int bbelow)
        {
            long maximumDigitalSum = 1;

            for (int a = 1; a < abelow; a++)
            {
                List <int> aliste = DigitsList.ConvertToDigitListe(1);
                for (int b = 1; b < bbelow; b++)
                {
                    aliste = DigitsList.Product(aliste, a);

                    var digitalSum = aliste.Sum();
                    if (digitalSum > maximumDigitalSum)
                    {
                        maximumDigitalSum = digitalSum;
                    }
                }
            }
            return(maximumDigitalSum);
        }
        public int GetNumberIntegerWhichAreNthPoweres()
        {
            int numberIntegerWhichAreNthPoweres = 0;

            for (int x = 1; x < 10; x++)
            {
                List <int> powerNumber = new List <int> {
                    x
                };                                           //larger than long

                int nthPower = 1;
                while (powerNumber.Count == nthPower)
                {
                    numberIntegerWhichAreNthPoweres++;
                    powerNumber = DigitsList.Product(powerNumber, x);
                    nthPower++;
                }
            }

            return(numberIntegerWhichAreNthPoweres);
        }
Beispiel #9
0
        public int GetNumberOfDistinctTerms(int amax, int bmax)
        {
            /*   Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:    */

            List <string> numberAsStringListe = new List <string>();

            for (var a = 2; a <= amax; a++)
            {
                List <int> digitlist = new List <int>()
                {
                    a
                };

                for (var b = 2; b <= bmax; b++)
                {
                    digitlist = DigitsList.Product(digitlist, multiplier: a);
                    numberAsStringListe.Add(digitlist.StringFromArrayReverse());
                }
            }

            var numberOfDistinctTerms = numberAsStringListe.Distinct().Count();

            return(numberOfDistinctTerms);
        }