Find the missing digit in given product of large positive integers | Function to find the replaced digit in the product of a * b ; Keeps track of the sign of the current digit ; Stores the value of a % 11 ; Find the value of a mod 11 for large value of a as per the derived formula ; Stores the value of b % 11 ; Find the value of b mod 11 for large value of a as per the derived formula ; Stores the value of c % 11 ; Keeps track of the sign of x ; If the current digit is the missing digit , then keep the track of its sign ; Find the value of x using the derived equation ; Check if x has a negative sign ; Return positive equivaluent of x mod 11 ; Driver Code
def findMissingDigit ( a , b , c ) : NEW_LINE INDENT w = 1 NEW_LINE a_mod_11 = 0 NEW_LINE for i in range ( len ( a ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT a_mod_11 = ( a_mod_11 + w * ( ord ( a [ i ] ) - ord ( '0' ) ) ) % 11 NEW_LINE w = w * - 1 NEW_LINE DEDENT b_mod_11 = 0 NEW_LINE w = 1 NEW_LINE for i in range ( len ( b ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT b_mod_11 = ( b_mod_11 + w * ( ord ( b [ i ] ) - ord ( '0' ) ) ) % 11 NEW_LINE w = w * - 1 NEW_LINE DEDENT c_mod_11 = 0 NEW_LINE xSignIsPositive = True NEW_LINE w = 1 NEW_LINE for i in range ( len ( c ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( c [ i ] == ' x ' ) : NEW_LINE INDENT xSignIsPositive = ( w == 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT c_mod_11 = ( c_mod_11 + w * ( ord ( c [ i ] ) - ord ( '0' ) ) ) % 11 NEW_LINE DEDENT w = w * - 1 NEW_LINE DEDENT x = ( ( a_mod_11 * b_mod_11 ) - c_mod_11 ) % 11 NEW_LINE if ( not xSignIsPositive ) : NEW_LINE INDENT x = - x NEW_LINE DEDENT return ( x % 11 + 11 ) % 11 NEW_LINE DEDENT A = "123456789" NEW_LINE B = "987654321" NEW_LINE C = "12193263111x635269" NEW_LINE print ( findMissingDigit ( A , B , C ) ) NEW_LINE