Exemplo n.º 1
0
 static void Main(string[] args)
 {
     primes = new List<int>();
     for (int i = 1000; i <= 9999; i++)
     {
         if (pg.CheckPrime(i,false))
             primes.Add(i);
     }
     
     List<string> result = new List<string>();
     foreach (int prime in primes)
     {
         if (prime == 2969)
         {
             Console.WriteLine();
         }
         int[] nums = BuildSeqNumbers(prime,true);
         if (nums.Count() < 3)
             continue;
         List<int[]> tripleGroup = PermutationProvider.BuildPermutation<int>(nums, 3);
         foreach (int[] triple in tripleGroup)
         {
             int[] temptpl = triple.OrderBy(x => x).ToArray();
             if ((temptpl[2] - temptpl[1]) != (temptpl[1] - temptpl[0]))
                 continue;
             string item = string.Format("{0}{1}{2}", temptpl[0], temptpl[1], temptpl[2]);
             if (result.Contains(item))
                 continue;
             result.Add(item);
         }
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int Min = int.MaxValue;

            BuildPenNums();
            List <int[]> penPairs = PermutationProvider.BuildPermutation <int>(penNums, 2);

            foreach (int[] penpair in penPairs)
            {
                int temp = Math.Abs(penpair[0] - penpair[1]);
                if (temp >= Min)
                {
                    continue;
                }
                if (!penNums.Contains(temp))
                {
                    continue;
                }
                int temp2 = penpair[0] + penpair[1];
                if (!penNums.Contains(temp2))
                {
                    continue;
                }
                Min = temp;
            }
            Console.WriteLine("Result is {0}", Min);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            prime = new PrimeGenerator().CheckPrimeNumber(7654321);
            int result = 0;

            for (int i = 7; i > 0; i--)
            {
                int[] tempSeeds = new int[i];
                for (int j = i; j > 0; j--)
                {
                    tempSeeds[i - j] = j;
                }
                List <int[]> digitsList = PermutationProvider.BuildPermutation <int>(tempSeeds, i);
                foreach (int[] digits in digitsList)
                {
                    int num = 0;
                    for (int k = 0; k < digits.Length; k++)
                    {
                        num += digits[k] * (int)Math.Pow(10, k);
                    }
                    if (!prime[num])
                    {
                        continue;
                    }
                    result = num;
                    break;
                }
                if (result > 0)
                {
                    break;
                }
            }
            Console.WriteLine(string.Format("Result is {0}", result));
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            List <int[]> seeds = PermutationProvider.BuildPermutation <int>(numbers, 9);

            foreach (int[] seed in seeds)
            {
                BuildAndCheckFormula(seed);
            }
            int result = products.Distinct().Sum();

            Console.WriteLine(result);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            int[]        seeds  = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            List <int[]> result = PermutationProvider.BuildPermutation <int>(seeds, 10);
            long         total  = 0;

            foreach (int[] digits in result)
            {
                if (digits[0] == 0)
                {
                    continue;
                }
                // 2 - 4
                if (digits[3] % 2 != 0)
                {
                    continue;
                }
                // 3 - 5
                if ((digits[2] + digits[3] + digits[4]) % 3 != 0)
                {
                    continue;
                }
                // 4 - 6
                if (digits[5] != 0 && digits[5] != 5)
                {
                    continue;
                }
                // 5 - 7
                if (BuildNum(digits[4], digits[5], digits[6]) % 7 != 0)
                {
                    continue;
                }
                // 6 - 8
                if (BuildNum(digits[5], digits[6], digits[7]) % 11 != 0)
                {
                    continue;
                }
                // 7 - 9
                if (BuildNum(digits[6], digits[7], digits[8]) % 13 != 0)
                {
                    continue;
                }
                // 8 - 10
                if (BuildNum(digits[7], digits[8], digits[9]) % 17 != 0)
                {
                    continue;
                }
                total += BuildLong(digits);
            }
            Console.WriteLine(string.Format("Result is {0}", result));
        }
Exemplo n.º 6
0
        static void BuildNumbersToCheck()
        {
            int[]        seeds      = new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 };
            List <int[]> digitsList = PermutationProvider.BuildPermutation <int>(seeds, 9);

            pandigitals = new bool[1000000000];
            foreach (int[] digits in digitsList)
            {
                long temp = 0;
                for (int i = 8; i >= 0; i--)
                {
                    temp  = temp * 10;
                    temp += digits[i];
                }
                pandigitals[temp] = true;
            }
        }
Exemplo n.º 7
0
 static int[] BuildSeqNumbers(int num,bool checkPrime)
 {
     int[] basedigits = NumberUtils.SplitNumber((long)num, 1);
     List<int[]> digitsList = PermutationProvider.BuildPermutation<int>(basedigits, basedigits.Length);
     List<int> result = new List<int>();
     foreach (int[] digits in digitsList) {
         int tmp = 0;
         if (digits[0] == 0)
             continue;
         foreach (int digit in digits)
         {
             tmp *= 10;
             tmp += digit;
         }
         if (result.Contains(tmp))
             continue;
         if (!primes.Contains(tmp))
             continue;
         result.Add(tmp);
     }
     return result.ToArray();
 }