コード例 #1
0
        public int Run(int count)
        {
            int initValue        = GetMaxNumber(count);
            int largestPalindrom = 1;

            for (int firstNumber = initValue; firstNumber > 0; --firstNumber)
            {
                bool hasLargeValue = false;

                for (int secondNumber = initValue; secondNumber > 0; --secondNumber)
                {
                    int suggestedPalindrom = secondNumber * firstNumber;
                    if (suggestedPalindrom > largestPalindrom)
                    {
                        hasLargeValue = true;
                        if (SpecialNumbers.IsPalindrome(suggestedPalindrom))
                        {
                            largestPalindrom = suggestedPalindrom;
                        }
                    }
                }

                if (!hasLargeValue)
                {
                    break;
                }
            }
            return(largestPalindrom);
        }
コード例 #2
0
        public long Run(int maxNumber)
        {
            long sum = 0;

            for (int i = 1; i < maxNumber; i += 2)
            {
                if (SpecialNumbers.IsPalindrome(i, 10) && SpecialNumbers.IsPalindrome(i, 2))
                {
                    sum += i;
                }
            }
            return(sum);
        }