Count three | Function to count three - digit numbers having difference x with its reverse ; If x is not multiple of 99 ; No solution exists ; Generate all possible pairs of digits [ 1 , 9 ] ; If any pair is obtained with difference x / 99 ; Increase count ; Return the count ; Driver Code
def Count_Number ( x ) : NEW_LINE INDENT ans = 0 ; NEW_LINE if ( x % 99 != 0 ) : NEW_LINE INDENT ans = - 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT diff = x / 99 ; NEW_LINE for i in range ( 1 , 10 ) : NEW_LINE INDENT for j in range ( 1 , 10 ) : NEW_LINE INDENT if ( ( i - j ) == diff ) : NEW_LINE INDENT ans += 10 ; NEW_LINE DEDENT DEDENT DEDENT DEDENT return ans ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x = 792 ; NEW_LINE print ( Count_Number ( x ) ) ; NEW_LINE DEDENT