Rotate digits of a given number by K | Function to find the count of digits in N ; Stores count of digits in N ; Calculate the count of digits in N ; Update digit ; Update N ; Function to rotate the digits of N by K ; Stores count of digits in N ; Update K so that only need to handle left rotation ; Stores first K digits of N ; Remove first K digits of N ; Stores count of digits in left_no ; Append left_no to the right of digits of N ; Driver Code ; Function Call
def numberOfDigit ( N ) : NEW_LINE INDENT digit = 0 NEW_LINE while ( N > 0 ) : NEW_LINE INDENT digit += 1 NEW_LINE N //= 10 NEW_LINE DEDENT return digit NEW_LINE DEDENT def rotateNumberByK ( N , K ) : NEW_LINE INDENT X = numberOfDigit ( N ) NEW_LINE K = ( ( K % X ) + X ) % X NEW_LINE left_no = N // pow ( 10 , X - K ) NEW_LINE N = N % pow ( 10 , X - K ) NEW_LINE left_digit = numberOfDigit ( left_no ) NEW_LINE N = N * pow ( 10 , left_digit ) + left_no NEW_LINE print ( N ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N , K = 12345 , 7 NEW_LINE rotateNumberByK ( N , K ) NEW_LINE DEDENT