human
Largest palindrome which is product of two N | Function to check if a number is a Palindrome or not.
Taking the string value of the number.
Loop to check if every i - th character from beginning is equal to every ( N - i ) th char.
Function to find the largest palindrome which is a product of two N digited numbers.
Find lowerBound , upperBound for a given nDigits . for n = 2 [ 10 , 99 ].
Result variables.
Keep p decrementing by 11.
Find the nearest number divisible by 11.
Keep decrementing q by 1.
Update the result if t > r and is a palindrome.
Printing the final result.
Driver code"
How can the above be solved in Python?
 ... Give me a code to largest palindrome which is product of two N and the other steps required?
assistant
#Here is code to largest palindrome which is product of two N and the other steps required.
 def isPalindrome ( x ) :
	num = str ( x )
	result = True
	i = 0
	j = len ( num ) - 1
	while ( i < j and result ) :
		result = num [ i ] == num [ j ]
		i += 1
		j -= 1
	return result
def find ( nDigits ) :
	lowerBound = pow ( 10 , nDigits - 1 )
	upperBound = ( lowerBound * 10 ) - 1
	resultP = 0
	resultQ = 0
	resultR = 0
	for p in range ( upperBound , lowerBound , - 11 ) :
		while ( p % 11 != 0 ) :
			p -= 1
		for q in range ( upperBound , lowerBound , - 1 ) :
			t = p * q
			if ( t > resultR and isPalindrome ( t ) ) :
				resultP = p
				resultQ = q
				resultR = t
				break
	print ( resultR )
if __name__ == " _ _ main _ _ " :
	N = 2
	find ( N )