XOR and OR of all N | Function to check if a number is palindrome or not ; Convert the num n to string ; Iterate over string to check whether it is palindromic or not ; Function to find XOR of all N - digits palindrome number ; To store the XOR and OR of all palindromic number ; Starting N - digit palindromic number ; Ending N - digit palindromic number ; Iterate over starting and ending number ; To check if i is palindromic or not ; Print the XOR and OR of all palindromic number ; Driver Code
def ispalin ( num ) : NEW_LINE INDENT s = str ( num ) ; NEW_LINE st = 0 ; NEW_LINE ed = len ( s ) - 1 ; NEW_LINE while ( st <= ed ) : NEW_LINE INDENT if ( s [ st ] != s [ ed ] ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT st += 1 ; NEW_LINE ed -= 1 ; NEW_LINE DEDENT return True ; NEW_LINE DEDENT def CalculateXORandOR ( n ) : NEW_LINE INDENT CalculateXOR = 0 ; NEW_LINE CalculateOR = 0 ; NEW_LINE start = 10 ** ( n - 1 ) ; NEW_LINE end = ( 10 ** n ) - 1 ; NEW_LINE for i in range ( start , end + 1 ) : NEW_LINE INDENT if ( ispalin ( i ) ) : NEW_LINE INDENT CalculateXOR = CalculateXOR ^ i ; NEW_LINE CalculateOR = CalculateOR | i ; NEW_LINE DEDENT DEDENT print ( " XOR ▁ = " , CalculateXOR , end = " ▁ " ) ; NEW_LINE print ( " OR ▁ = ▁ " , CalculateOR ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 4 ; NEW_LINE CalculateXORandOR ( n ) ; NEW_LINE DEDENT