public string Compute()
        {
            long   result = 0;
            string digits = null;

            for (int digit = 1; digit <= 9; digit++)
            {
                digits += digit.ToString();
                Premutations premutations = new Premutations(digits);
                for (int index = 1; index <= premutations.Count(); index++)
                {
                    string premutation = premutations.GetPremutation(index);
                    long   candidate   = long.Parse(premutation);
                    if (candidate > result)
                    {
                        if (MathLibrary.IsPrime(candidate))
                        {
                            result = candidate;
                        }
                    }
                }
            }

            return(result.ToString());
        }
Example #2
0
        public string Compute()
        {
            List <long> primeNumbers = MathLibrary.GetPrime(9999);

            for (long candidate = 1000; candidate <= 9999; candidate++)
            {
                if (candidate.Equals(1487) | candidate.Equals(4817) | candidate.Equals(8147))
                {
                    continue;                                                                             // ignore the sample case
                }
                if (!primeNumbers.Contains(candidate))
                {
                    continue;                                                                             // ignore when the first number is not prime
                }
                string       startSequence = candidate.ToString();
                Premutations premutations  = new Premutations(startSequence);
                for (long index1 = 2; index1 < premutations.Count(); index1++)
                {
                    for (long index2 = index1 + 1; index2 <= premutations.Count(); index2++)
                    {
                        string secondString = premutations.GetPremutation(index1);
                        long   secondNumber = long.Parse(secondString);
                        if (candidate == secondNumber)
                        {
                            continue;                                                                     // ignore if the first and second are the same
                        }
                        if (!primeNumbers.Contains(secondNumber))
                        {
                            continue;                                                                     // ignore if the second is not prime
                        }
                        string thirdString = premutations.GetPremutation(index2);
                        long   thirdNumber = long.Parse(thirdString);
                        if (candidate == thirdNumber)
                        {
                            continue;                                                                     // Ignore if the first and third are the same
                        }
                        if (!primeNumbers.Contains(thirdNumber))
                        {
                            continue;                                                                     // Ignore if the third number is not prime
                        }
                        if (secondNumber != thirdNumber)
                        {
                            if (Math.Abs(secondNumber - candidate) == Math.Abs(thirdNumber - secondNumber))
                            {
                                return(candidate + secondString + thirdString);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Example #3
0
        public string Compute()
        {
            long         result       = 0;
            Premutations premutations = new Premutations("0123456789");

            for (long index = 1; index <= premutations.Count(); index++)
            {
                string premutation = premutations.GetPremutation(index);
                if (long.Parse(premutation.Substring(1, 3)) % 2 > 0)
                {
                    continue;
                }
                if (long.Parse(premutation.Substring(2, 3)) % 3 > 0)
                {
                    continue;
                }
                if (long.Parse(premutation.Substring(3, 3)) % 5 > 0)
                {
                    continue;
                }
                if (long.Parse(premutation.Substring(4, 3)) % 7 > 0)
                {
                    continue;
                }
                if (long.Parse(premutation.Substring(5, 3)) % 11 > 0)
                {
                    continue;
                }
                if (long.Parse(premutation.Substring(6, 3)) % 13 > 0)
                {
                    continue;
                }
                if (long.Parse(premutation.Substring(7, 3)) % 17 > 0)
                {
                    continue;
                }
                result += long.Parse(premutation);
            }

            return(result.ToString());
        }