Exemplo n.º 1
0
        public static int truncatableprimes(int n)
        {
            int count = 0;
            int sum   = 0;

            PrimeFunctions.GeneratePrimesToList(1000000);
            PrimeFunctions.ConvertToHash();
            int i = 4;

            while (count < n)
            {
                bool       isprime = true;
                List <int> trunc   = CombinatoricFunctions.truncations(PrimeFunctions.PrimeList[i]);
                foreach (int truncation in trunc)
                {
                    if (!PrimeFunctions.PrimeListHash.Contains(truncation))
                    {
                        isprime = false;
                        break;
                    }
                }
                if (isprime)
                {
                    count++;
                    sum += PrimeFunctions.PrimeList[i];
                }
                i++;
            }
            return(sum);
        }
Exemplo n.º 2
0
        public static long PandigitalMultiples(long n)
        {
            long maxpandigital = 1;

            for (int i = 1; i < n; i++)
            {
                long mult = i;
                int  k    = 2;
                while (mult < 1000000000)
                {
                    mult = CombinatoricFunctions.concatenatenum(mult, k * i);
                    if (mult > 100000000 && mult < 1000000000)
                    {
                        if (MiscFunctions.IsPandigital((int)mult))
                        {
                            if (mult > maxpandigital)
                            {
                                maxpandigital = mult;
                            }
                        }
                    }
                    k++;
                }
            }
            return(maxpandigital);
        }
Exemplo n.º 3
0
        public static int CirculuarPrimes(int n)
        {
            PrimeFunctions.GeneratePrimesTillNToList(1000000);
            PrimeFunctions.ConvertToHash();

            int count = 0;

            for (int i = 2; i < n; i++)
            {
                List <int> rots  = CombinatoricFunctions.rotations(i);
                bool       prime = true;
                foreach (int rot in rots)
                {
                    if (!PrimeFunctions.PrimeListHash.Contains(rot))
                    {
                        prime = false;
                        break;
                    }
                }
                if (prime)
                {
                    count++;
                    //Console.WriteLine(i);
                }
            }
            return(count);
        }
Exemplo n.º 4
0
        public static int DoubleBasePalindromes(int n)
        {
            int sum = 0;

            for (int i = 1; i < n; i++)
            {
                string binary = Convert.ToString(i, 2);
                if (CombinatoricFunctions.IsPalindrome(i) && CombinatoricFunctions.IsPalindrome(binary))
                {
                    sum += i;
                }
            }
            return(sum);
        }
Exemplo n.º 5
0
        public static int DigitFactorials(int n)
        {
            int sum = 0;

            CombinatoricFunctions.generatefactorial(10);
            for (int i = 3; i < n; i++)
            {
                int[]      digits  = MiscFunctions.DigitsFromInt(i);
                BigInteger tempsum = 0;
                foreach (int digit in digits)
                {
                    tempsum += CombinatoricFunctions.factorial(digit);
                }
                if (tempsum == i)
                {
                    sum += i;
                }
            }
            return(sum);
        }
Exemplo n.º 6
0
        public static int LargestPalindromeProduct(int n)
        {
            int largest = 0;

            //Loop through every combination of numbers until n
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    //If i*j is a palindrome then check if it's largest then the largest so far and set it to an int
                    if (CombinatoricFunctions.IsPalindrome(i * j))
                    {
                        if ((i * j) > largest)
                        {
                            largest = i * j;
                        }
                    }
                }
            }
            return(largest);
        }
Exemplo n.º 7
0
 public static int FactorialDigitSum(int n)
 {
     return(MiscFunctions.SumOfDigits(CombinatoricFunctions.factorial(n)));
 }
Exemplo n.º 8
0
 public static string LatticePathsFast(int n)
 {
     return(CombinatoricFunctions.binomialcoeff(2 * n, n).ToString());
 }