示例#1
0
 /*
  *     145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
  */
 public bool IsCuriousNumber(int number)
 {
     return(number == DigitsList
            .ConvertToDigitListe(number)
            .Select(digit => FactorialArray[digit])
            .Sum());
 }
        public int GetShortestPossiblePasscode(int[] table)
        {
            int shortestPossiblePasscode = 0;

            HashSet <int>[] trailingNumbersSet = new HashSet <int> [10];
            for (int i = 0; i < 10; i++)
            {
                trailingNumbersSet[i] = new HashSet <int>();
            }

            HashSet <int> foundDigits = new HashSet <int>();


            for (int linenr = 0; linenr < table.Length; linenr++)
            {
                var digitsList = DigitsList.ConvertToDigitListe(table[linenr]);
                trailingNumbersSet[digitsList[2]].Add(digitsList[1]);
                trailingNumbersSet[digitsList[2]].Add(digitsList[0]);
                trailingNumbersSet[digitsList[1]].Add(digitsList[0]);

                foundDigits.Add(digitsList[0]);
                foundDigits.Add(digitsList[1]);
                foundDigits.Add(digitsList[2]);
            }

            var l = foundDigits.OrderBy(i => trailingNumbersSet[i].Count()).ToList();

            shortestPossiblePasscode = DigitsList.ConvertToNumber(l);

            return(shortestPossiblePasscode);
        }
        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);
        }
        public void TestConvertToDigitListe()
        {
            var digitsList = DigitsList.ConvertToDigitListe(12345);

            Assert.Equal(5, digitsList.Count);
            Assert.Equal(5, digitsList[0]);;
            Assert.Equal(1, digitsList[4]);;
        }
        public bool IsLychrelNumber(long number)
        {
            bool       isPalindrome      = false;
            int        numberOfIteration = 0;
            List <int> digits            = DigitsList.ConvertToDigitListe(number);

            while (!isPalindrome && numberOfIteration < 50)
            {
                digits = DigitsList.Sum(digits, DigitsList.ReverseCopy(digits));

                isPalindrome = Palindrome.IsPalindrome(digits);
                numberOfIteration++;
            }
            return(!isPalindrome);
        }
        private bool IsPermutations(long n1, long n2, long n3)
        {
            var liste1 = DigitsList.ConvertToDigitListe(n1).OrderBy(e => e).ToArray();
            var liste2 = DigitsList.ConvertToDigitListe(n2).OrderBy(e => e).ToArray();
            var liste3 = DigitsList.ConvertToDigitListe(n3).OrderBy(e => e).ToArray();

            for (int i = 0; i < 4; i++)
            {
                if (liste1[i] != liste2[i] || liste1[i] != liste3[i])
                {
                    return(false);
                }
            }

            return(true);
        }
示例#7
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()));
        }
示例#8
0
        public static bool IsPandigita(int value, int max)
        {
            int [] digitsArray = DigitsList.ConvertToDigitListe(value).OrderBy(e => e).ToArray();


            if (digitsArray.Length != max)
            {
                return(false);
            }
            for (int i = 1; i <= max; i++)
            {
                if (digitsArray[i - 1] != i)
                {
                    return(false);
                }
            }

            return(true);;
        }
        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);
        }
        /*
         *
         *    Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note the following:
         *    d2d3d4=406 is divisible by 2
         *    d3d4d5=063 is divisible by 3
         *    d4d5d6=635 is divisible by 5
         *    d5d6d7=357 is divisible by 7
         *    d6d7d8=572 is divisible by 11
         *    d7d8d9=728 is divisible by 13
         *    d8d9d10=289 is divisible by 17
         */

        public bool HasSubstringdivisibility(long number)
        {
            var digitListe = DigitsList.ConvertToDigitListe(number);

            digitListe.Reverse();
            var digitArray = digitListe.ToArray();

            int[] dividors = { 2, 3, 5, 7, 11, 13, 17 };

            for (int i = 0; i < dividors.Length; i++)
            {
                int value = DigitsList.ConvertToNumberHighesFirst(digitArray.Skip(i + 1).Take(3).ToArray());
                if (value % dividors[i] != 0)
                {
                    return(false);
                }
            }

            return(true);
        }
        public int GetSumOfPower(int po)
        {
            int sumOfPower = 0;

            //etter denne verdien vil n alltid være større en powerOfNumber
            int max = 9 * 9 * 9 * 9 * 9 * 6;

            int n = 2;

            while (n < max)
            {
                int powerOfNumber = DigitsList.ConvertToDigitListe(n).Select(d => pow(d, po)).Sum();

                if (powerOfNumber == n)
                {
                    sumOfPower += powerOfNumber;
                }
                n++;
            }

            return(sumOfPower);
        }
        public bool IsTruncatableprime(int number)
        {
            var digits = DigitsList.ConvertToDigitListe(number);

            for (int i = 0; i < digits.Count; i++)
            {
                if (!IsPrime(DigitsList.ConvertToNumber(digits.Skip(i).ToList())))
                {
                    return(false);
                }
            }

            for (int i = 1; i < digits.Count; i++)
            {
                if (!IsPrime(DigitsList.ConvertToNumber(digits.SkipLast(i).ToList())))
                {
                    return(false);
                }
            }

            return(true);
        }
        public int GetBelow(int below)
        {
            int        counter     = 0;
            List <int> digitsListe = DigitsList.ConvertToDigitListe(0);

            for (int i = 1; i < below; i++)
            {
                digitsListe = DigitsList.Add1(digitsListe);

                if (i % 10 == 0)
                {
                    continue;
                }
                int count = digitsListe.Count();

                bool reverible = true;
                int  rest      = 0;
                for (int d = 0; d < count; d++)
                {
                    int digitplusreverse = digitsListe[d] + digitsListe[count - d - 1] + rest;
                    int s = digitplusreverse % 10;

                    if (s % 2 == 0)
                    {
                        reverible = false;
                        break;
                    }
                    rest = digitplusreverse / 10;
                }

                if (reverible)
                {
                    counter++;
                }
            }

            return(counter);
        }
示例#14
0
        public bool IsCircularPrimes(int number)
        {
            var digits       = DigitsList.ConvertToDigitListe(number);
            int antallShifts = digits.Count;


            for (int index = 0; index < antallShifts; index++)
            {
                List <int> nyListe = new List <int>();
                for (int j = 0; j < antallShifts; j++)
                {
                    int t = digits[(j + index) % antallShifts];
                    nyListe.Add(t);
                }


                int number2 = DigitsList.ConvertToNumber(nyListe);
                if (!IsPrime(number2))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#15
0
        public int SumFactorialOfItsDigits(int number)
        {
            var digitsList = DigitsList.ConvertToDigitListe(number);

            return((int)digitsList.Select(i => Factorial.Factor(i)).Sum());
        }
示例#16
0
        private int SumSquareDigits(int number)
        {
            List <int> list = DigitsList.ConvertToDigitListe(number);

            return(list.Select(e => e * e).Sum());
        }