Exemplo n.º 1
0
        public void Run()
        {
            List <byte[]> oneToNineCombis = CombiUtils.IntCombinations(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 9);
            HashSet <int> products        = new HashSet <int>();
            int           product         = 0;

            foreach (byte[] pandigital in oneToNineCombis)
            {
                for (int i = 0; i < 8; i++)
                {
                    int firstInt = Int32.Parse(bytesToString(pandigital.Take(i + 1).ToArray()));
                    for (int j = i + 1; j < 8; j++)
                    {
                        int secondInt = Int32.Parse(bytesToString(pandigital.Skip(i + 1).Take(j - i).ToArray()));
                        product = Int32.Parse(bytesToString(pandigital.Skip(j + 1).ToArray()));
                        if (firstInt * secondInt == product && !products.Contains(product))
                        {
                            products.Add(product);
                        }
                    }
                }
            }

            BigInteger productsSum = products.Sum();

            this.result = productsSum.ToString();
        }
Exemplo n.º 2
0
        public void Run()
        {
            int n = 1, r = 0;
            int moreThanAMill = 0;

            while (n <= 100)
            {
                r = 0;
                while (n > r)
                {
                    BigInteger combis = CombiUtils.SelectRfromN(n, r);
                    if (combis >= 1000000)
                    {
                        moreThanAMill++;
                    }
                    r++;
                }
                n++;
            }
            this.result = moreThanAMill.ToString();
        }
Exemplo n.º 3
0
        public void Run()
        {
            for (int i = 1000; i < 10000; i++)
            {
                if (Primes.IsPrime(i))
                {
                    byte[] bytes =
                    {
                        Byte.Parse(i.ToString()[0].ToString()),
                        Byte.Parse(i.ToString()[1].ToString()),
                        Byte.Parse(i.ToString()[2].ToString()),
                        Byte.Parse(i.ToString()[3].ToString()),
                    };
                    List <byte[]> permutations   = CombiUtils.IntCombinations(bytes, 4);
                    List <int>    primes         = new List <int>();
                    List <int>    solutionPrimes = new List <int>();
                    foreach (byte[] perm in permutations)
                    {
                        int prime = Int32.Parse(bytesToString(perm));
                        if (Primes.IsPrime(prime))
                        {
                            primes.Add(prime);
                        }
                    }
                    primes.Sort();
                    primes = primes.Where(x => x.ToString().Length == 4).ToList();
                    for (int firstIndex = 0; firstIndex < primes.Count(); firstIndex++)
                    {
                        bool found       = false;
                        int  secondIndex = 1;
                        while (secondIndex < primes.Count())
                        {
                            int diff = primes[secondIndex] - primes[firstIndex];
                            for (int l = primes.Count - 1; l > secondIndex; l--)
                            {
                                if (diff == primes[l] - primes[secondIndex] && diff != 0)
                                {
                                    solutionPrimes.Add(primes[firstIndex]);
                                    solutionPrimes.Add(primes[secondIndex]);
                                    solutionPrimes.Add(primes[l]);
                                    found = true;
                                    break;
                                }
                            }
                            if (found)
                            {
                                break;
                            }
                            secondIndex++;
                        }
                        if (found)
                        {
                            break;
                        }
                    }

                    if (solutionPrimes.Count == 3)
                    {
                        if (solutionPrimes[1] - solutionPrimes[0] == solutionPrimes[2] - solutionPrimes[1])
                        {
                            Console.WriteLine("Prime 1: {0} Prime 2: {1} Prime 3: {2} - Diff value: {3}",
                                              solutionPrimes[0],
                                              solutionPrimes[1],
                                              solutionPrimes[2],
                                              solutionPrimes[2] - primes[1]
                                              );
                        }

                        if (solutionPrimes[0] != 1487)
                        {
                            this.result = solutionPrimes[0] + "" + solutionPrimes[1] + "" + solutionPrimes[2];
                            return;
                        }
                    }
                }
            }
        }