public int GetLargestPalindrome(int power)
        {
            int        offset          = (int)Math.Pow(1, power - 1);
            int        limit           = (int)Math.Pow(10, power);
            List <int> twoDigitNumbers = Enumerable.Range(offset, limit - offset).Select(x => x++).Reverse().ToList();
            var        query           = (
                from row in twoDigitNumbers
                from col in twoDigitNumbers
                orderby row descending, col descending
                select new { row, col });

            int        max        = 0;
            Palindrome palindrome = new Palindrome();

            foreach (var value in query)
            {
                var product = value.row * value.col;
                if (palindrome.IsPalindrome(product.ToString()) && product > max)
                {
                    max = product;
                }
            }

            return(max);
        }
Ejemplo n.º 2
0
        public void ReturnTrueIfInputLengthIsOne()
        {
            const int input = 1;

            bool actualValue = new Palindrome().IsPalindrome(input.ToString());

            Assert.True(actualValue);
        }
Ejemplo n.º 3
0
        public void TestPalindromeNumber(int input, bool expectedValue)
        {
            bool actualValue = new Palindrome().IsPalindrome(input.ToString());

            Assert.Equal(expectedValue, actualValue);
        }